-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
25 lines (21 loc) · 884 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
const express = require('express')
const compression = require('compression')
const bodyParser = require('body-parser')
const path = require('path')
const cors = require('cors')
const api = require('./api')
if (process.env.NODE_ENV !== 'production') require('dotenv').config()
const app = express()
const port = process.env.PORT || 5000
app.use(bodyParser.json())
app.use(compression())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.static(path.join(__dirname, 'client/build')))
app.use(cors({ origin: '*' }));
app.use('', api)
app.listen(port, error => {
if (error) throw error
console.log('Server running on port ' + port)
})
app.get('/service-worker.js', (req, res) => { res.sendFile(path.resolve(__dirname, '..', 'build', 'service-worker.js')) })
app.get('*', function (req, res) { res.sendFile(path.join(__dirname, 'client/build', 'index.html')) })