forked from sd880428/twitter-api-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (35 loc) · 1014 Bytes
/
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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
// require module
const methodOverride = require('method-override')
const session = require('express-session')
const express = require('express')
const cors = require('cors')
// require self-made module
const passport = require('./config/passport')
const { apis } = require('./routes')
// app setting
const app = express()
const port = process.env.PORT || 4000
app.use(express.urlencoded({ extended: true }))// req.body
app.use(methodOverride('_method'))
app.use(express.json())// json
app.use(cors())
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true
}))
app.use(passport.initialize())
app.use(passport.session())
app.use((req, res, next) => {
req.session.messages = [] // 重設錯誤訊息
next()
})
app.use('/api', apis)
app.get('/', (req, res) => {
res.send('welcome')
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
module.exports = app