-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (52 loc) · 1.81 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
56
57
58
59
60
// ENV
require('dotenv').config();
// DEPENDENCIES
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cors = require('cors')
const port = 1818;
const answerRouter = require('./routes/answerRouter')
const questionRouter = require('./routes/questionRouter')
const commentRouter = require('./routes/commentRouter')
const userRouter = require('./routes/userRouter')
const loginRouter = require('./routes/loginRouter')
const imageRouter=require('./routes/imageRouter')
const searchRouter=require('./routes/searchRouter')
const techTreeRouter =require('./routes/techTreeRouter')
const Admin = require('./firebase/index');
// Node.js의 native Promise 사용
mongoose.Promise = global.Promise;
// CONNECT TO MONGODB SERVER //process.env.MONGO_URI
mongoose.connect(process.env.MONGO_DATA, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('mongodb 연결 완료'))
.catch(e => console.error(e));
mongoose.set('useCreateIndex', true)
//CORS ALLOW 나중에는 사용방법 바꿔야 할 듯
//app.use(cors())
app.use(cors({
origin: true,
credentials: true
}));
// Static File Service
app.use(express.static('public'));
// Body-parser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//Cookie-parser
app.use(cookieParser());
//CONFIGURE ROUTER
app.get('/', (req, res) => {
res.end("TECT BACKEND")
})
app.use('/answer', answerRouter)
app.use('/question' , questionRouter)
app.use('/comment', commentRouter)
app.use('/user', userRouter)
app.use('/login', loginRouter)
app.use('/image', imageRouter)
app.use('/search',searchRouter)
app.use('/techTree', techTreeRouter)
app.listen(port, () => console.log(`Server listening on port ${port}`));