-
Notifications
You must be signed in to change notification settings - Fork 2
/
serve.js
48 lines (34 loc) · 1.35 KB
/
serve.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
// Production Server file
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
const mongoUtil = require('./src/js/server/utils/mongoUtil.js');
const PORT = process.env.PORT || 80;
// Allow JSON and urlencoded
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// Allow static files
app.use(express.static(path.join(__dirname, 'build')));
// Connect to DB before opening routes
mongoUtil.connectToServers((err, connection) => {
if (err) throw err;
console.log("DB connections success.");
require('./src/js/server/utils/passportUtil.js').setupPassport(app);
// Setup API routes
app.use('/api/', require('./src/js/server/api/_login.js'));
app.use('/api/', require('./src/js/server/api/_user.js'));
app.use('/api/', require("./src/js/server/api/_store.js"));
app.use('/api/', require('./src/js/server/api/_event.js'));
app.use('/api/', require('./src/js/server/api/_invite.js'));
app.use('/api/', require('./src/js/server/api/_cron.js'));
// Setup VIEW routes (Allow react-router-dom to handle view routing)
app.use('*', (req ,res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Initialize App
app.listen(PORT, (app) =>
console.log("App listening on port " + PORT + "...")
);
});
module.exports = app;