-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (44 loc) · 1.32 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require('express');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');
const app = express();
require('dotenv').config();
const port = process.env.PORT || 3000;
const db = process.env.MONGODB_URI;
mongoose.connect(db)
.then(()=>{
console.log("conected to mongodb");
}).catch(error => {
console.log("mongo error",error);
}
);
//라우트 가져오기
const userRouter = require('./routes/user');
const authRouter = require('./routes/auth');
const mentoringRoutes = require('./routes/mentoringRoutes');
// 쿠키, 세션 설정
app.use(cookieParser(process.env.COOKIE_SECRET));
app.use(session({
secret: process.env.COOKIE_SECRET,
resave: false,
saveUninitialized: false,
}));
// passport 설정
const passportConfig = require('./passport');
passportConfig();
app.use(passport.initialize());
app.use(passport.session());
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.get('/', (req, res)=> {
res.end("Hello Snust");
})
//라우트 정의
app.use('/api/user', userRouter);
app.use('/auth', authRouter);
app.use('/api/mentoring', mentoringRoutes);
app.listen(port, async() => {
console.log(`Server running at http://localhost:${port}`);
});