-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (42 loc) · 1.65 KB
/
server.js
File metadata and controls
49 lines (42 loc) · 1.65 KB
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
const express = require('express')
const cors = require('cors')
const path = require('path')
const cookieParser = require('cookie-parser')
const app = express()
const http = require('http').createServer(app)
// Express App Config
app.use(cookieParser())
app.use(express.json({ limit: '50mb' }))
// app.use(express.bodyParser({ limit: '50mb' }))
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.resolve(__dirname, 'public/build')))
} else {
const corsOptions = {
origin: ['http://127.0.0.1:8080', 'http://localhost:8080', 'http://127.0.0.1:3000', 'http://localhost:3000'],
credentials: true,
}
app.use(cors(corsOptions))
}
const authRoutes = require('./api/auth/auth.routes')
const userRoutes = require('./api/user/user.routes')
const wapRoutes = require('./api/wap/wap.routes')
const { setupSocketAPI } = require('./services/socket.service')
// routes
const setupAsyncLocalStorage = require('./middlewares/setupAls.middleware')
app.all('*', setupAsyncLocalStorage)
app.use('/api/auth', authRoutes)
app.use('/api/user', userRoutes)
app.use('/api/wap', wapRoutes)
setupSocketAPI(http)
// Make every server-side-route to match the index.html
// so when requesting http://localhost:3030/index.html/car/123 it will still respond with
// our SPA (single page app) (the index.html file) and allow vue/react-router to take it from there
app.get('/**', (req, res) => {
res.sendFile(path.join(__dirname, 'public/build', 'index.html'))
})
const logger = require('./services/logger.service')
const req = require('express/lib/request')
const port = process.env.PORT || 3030
http.listen(port, () => {
logger.info('Server is running on port: ' + port)
})