forked from ALPHACamp/twitter-api-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (42 loc) · 1.13 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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const express = require('express')
const routes = require('./routes')
const methodOverride = require('method-override')
const passport = require('./config/passport')
const cors = require('cors')
const app = express()
// create socket.io server
const { createServer } = require('http')
const httpServer = createServer(app)
const io = require('socket.io')(httpServer, {
cors: {
origin: '*',
credentials: true
}
})
const useSocket = require('./socket/index')
const port = process.env.PORT || 3000
// middleware
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(passport.initialize())
app.use(methodOverride('_method'))
// cors
app.use(
cors({
// origin: 'https://zebrrrra.github.io',
origin: '*',
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']
})
)
// routes
app.get('/', (req, res) => { res.send('Welcome to the real world!') })
app.use(routes)
// use socket modules
useSocket(io)
// start
httpServer.listen(port, () => console.log(`Server running on port:${port}!`))
module.exports = app