-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (26 loc) · 884 Bytes
/
Copy pathindex.js
File metadata and controls
34 lines (26 loc) · 884 Bytes
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
const express = require('express')
const http = require('http')
const bodyParser = require('body-parser')
const cors = require('cors')
const path = require('path');
const { startCronUpdater } = require('./utils/dataUpdate')
const app = express()
// Middleware
app.use(cors())
app.use(bodyParser.json())
app.use(express.static('./client/build'))
// Routes for API
const populationRouter = require('./controllers/population')
const emissionsRouter = require('./controllers/emissions')
const apiUrl = '/api'
app.use(`${apiUrl}/population`, populationRouter)
app.use(`${apiUrl}/emissions`, emissionsRouter)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'));
});
const PORT = process.env.PORT || 4000
const server = http.createServer(app)
server.listen(PORT, () => {
startCronUpdater()
console.log(`Listening on port ${PORT}...`)
})