-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
51 lines (40 loc) · 1.43 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
46
47
48
49
50
51
import cluster from 'cluster';
import express from 'express';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import path from 'path';
import UserRoutes from './server/routes/UserRoutes';
import RoleRoutes from './server/routes/RoleRoutes';
import DocumentRoutes from './server/routes/DocumentRoutes';
import swagger from './server/routes/swagger';
if (cluster.isMaster) {
// Listen for dying workers
cluster.on('exit', (worker) => {
// Replace the dead worker,
// we're not sentimental
console.log('Worker %d died :(', worker.id);
cluster.fork();
});
}
const app = express();
const router = express.Router();
// Log requests to the console.
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use('/public', express.static(path.join(__dirname, 'client/public')));
swagger(router);
RoleRoutes.initializeRoutes(router);
UserRoutes.initializeRoutes(router);
DocumentRoutes.initializeRoutes(router);
app.use('/docs', express.static(path.join(__dirname, './server/swagger/')));
app.use(router);
// Setup a default catch-all route that sends back a welcome
// message in JSON format.
// configure our catch all routes
app.get('*', (request, response) => {
response.sendFile(path.join(__dirname, './client/public/index.html'));
});
app.listen(process.env.PORT || 8080);
console.log(`Server started on port ${process.env.PORT || 8080}`);
export default app;