-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
45 lines (36 loc) · 1.23 KB
/
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
37
38
39
40
41
42
43
44
45
const express = require('express');
const path = require('path');
const config = require('config');
const { i18nextMiddleware } = require('./lib/i18n')
const app = express();
app.use(express.json());
app.use(i18nextMiddleware)
app.use('/api/advisories', require('./routes/api/advisories'));
app.use('/api/auth', require('./routes/api/auth'));
app.use('/api/districts', require('./routes/api/districts'))
app.use('/api/organizations', require('./routes/api/organizations'));
app.use('/api/places', require('./routes/api/places'));
app.use('/api/themes', require('./routes/api/themes'))
app.use('/api/users', require('./routes/api/users'));
app.use('/api/visits', require('./routes/api/visits'));
if (config.production || config.test) {
app.use(express.static('client/build'));
app.get('*', (req,res) => {
res.sendFile(path.resolve(__dirname,'client','build','index.html'));
});
}
const port = config.server.port;
const listen = () => {
return app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
}
if (config.test) {
const httpShutdown = require('http-shutdown');
s = httpShutdown(listen());
s.host = `http://localhost:${port}`;
}
else {
s = listen();
}
module.exports = s;