-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (46 loc) · 1.41 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
const dotenv = require('dotenv')
const express = require('express')
const morgan = require('morgan')
const connectDB = require('./config/db')
// Load config
dotenv.config({
path: './config/config.env',
})
connectDB()
const app = express()
// Logging
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'))
}
// Use JSON
app.use(express.json())
// Enable Access-Control-Origin
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET,PUT,PATCH,POST,DELETE')
res.header('Access-Control-Allow-Headers', '*')
next()
})
// Able to GET images inside upload folder
app.use('/uploads', express.static('./uploads'))
// Routes
app.use(require('./routes/user_route'))
app.use(require('./routes/question_route'))
app.use(require('./routes/answer_route'))
app.use(require('./routes/tag_route'))
app.use(require('./routes/privilege_route'))
app.use(require('./routes/badge_route'))
app.use(require('./routes/article_route'))
app.use(require('./routes/comment_route'))
app.use(require('./routes/course_route'))
app.use(require('./routes/category_route'))
app.use(require('./routes/home_route'))
app.use(require('./routes/chat_route'))
app.use(require('./routes/search_route'))
const PORT = process.env.PORT || 3000
app.listen(
PORT,
console.log(
`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`
)
)