-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (27 loc) · 795 Bytes
/
server.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
const { createServer } = require('http');
const express = require('express');
const compression = require('compression');
const morgan = require('morgan');
const path = require('path');
const normalizePort = port => parseInt(port, 10)
const PORT = normalizePort(process.env.PORT || 5000)
console.log(PORT)
const app = express();
const dev = app.get('env') !== 'production'
if (!dev) {
app.disable('x-powered-by')
app.use(compression())
app.use(morgan('common'))
app.use(express.static(path.resolve(__dirname, 'build')))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'build', 'index.html'))
})
}
if (dev) {
app.use(morgan('dev'))
}
const server = createServer(app)
server.listen(PORT, err => {
if (err) throw err
console.log('Server Started')
})