인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

maliethy님의 프로필 이미지
maliethy

작성한 질문수

[리뉴얼] React로 NodeBird SNS 만들기

'우분투에 MySQL 설치하기'에서 EC2 back 서버에 404 ERROR가 뜹니다

해결된 질문

작성

·

227

0

mysql 설치해서 db연결하는 것까지는 성공했습니다. 그런데 back server에 접속하면 404 에러가 나와서요ㅜㅜ. 왜 그런지 감도 못잡고 있는 초보입니다. 도와주세요~

ubuntu@ip-172-31-47-106:~/Ymillonga/back$ sudo mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 42

Server version: 8.0.22 MySQL Community Server - GPL      

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use react-nodebird;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;

+--------------------------+

| Tables_in_react-nodebird |

+--------------------------+

| Follow                   |

| Hashtags                 |

| Like                     |

| PostHashtag              |

| comments                 |

| images                   |

| posts                    |

| users                    |

+--------------------------+

8 rows in set (0.00 sec)

mysql> exit;

Bye

app.js

const express = require('express');
const cors = require('cors');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const passport = require('passport');
const dotenv = require('dotenv');
const morgan = require('morgan');
const path = require('path');
const hpp = require('hpp');
const helmet = require('helmet');

const postRouter = require('./routes/post');
const postsRouter = require('./routes/posts');
const userRouter = require('./routes/user');
const hashtagRouter = require('./routes/hashtag');
const db = require('./models');
const passportConfig = require('./passport');

dotenv.config();
const app = express();
db.sequelize.sync()
    .then(() => {
        console.log('db연결 성공');
    })
    .catch(console.error);
passportConfig();

if (process.env.NODE_ENV === 'production') {
    app.use(morgan('combined'));
    app.use(hpp());
    app.use(helmet());
else {
    app.use(morgan('dev'));
}


app.use(cors({
    origin: ['http://localhost:3060''nodebird.com''http://52.79.186.162'],//'http://nodebird.com', 해당 주소에서 온 요청만 허용
    credentials: true,//true: cookie를 다른 도메인(3060 port에서 3065 port로 전달하는 경우)으로 전달하게 함
}));

app.use('/'express.static(path.join(__dirname'uploads')));// '/' => 'localhost:3065/모모.png',__dirname(현재폴더:back), __dirname + 'uploads'로 적지 않는다. 운영체제마다 /(맥),\(윈도우) 경로설정 다른 것을 자동으로 해준다. 
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser(process.env.COOKIE_SECRET));
app.use(session(
    {
        saveUninitialized: false,
        resave: false,
        secret: process.env.COOKIE_SECRET,
    }
));
app.use(passport.initialize());
app.use(passport.session());


app.use('/posts'postsRouter);
app.use('/post'postRouter);
app.use('/user'userRouter);
app.use('/hashtag'hashtagRouter);


// app.use((err, req, res, next) => {
//     //에러 처리 미들웨어를 특별하게 보이도록 하고 싶을 때 따로 만들어주기

// });
app.listen(80, () => {
    console.log('서버 실행 중');
});

답변 2

1

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

GET / 라우터를 안 만드신 것 아닌가요?

다른 라우터들 require해온 것은 보이는데 GET /는 보이지 않습니다. app.get('/')가 있어야 뜹니다.

0

maliethy님의 프로필 이미지
maliethy
질문자

앗 그걸 빼먹었군요 3분만에 답변 주셔서 깜짝 놀랐습니다 감사합니다

maliethy님의 프로필 이미지
maliethy

작성한 질문수

질문하기