-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (38 loc) · 1.29 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
/**
* Author: Sam Heutmaker [[email protected]]
*/
const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 8080;
const mongoose = require('mongoose');
const researcherRoutes = require('./server/routes/researcherRoutes');
const studyRoutes = require("./server/routes/studyRoutes");
const trialRoutes = require("./server/routes/trialRoutes");
const {
MONGO_DB_CONNECTION_STRING
} = require("./server/env.js");
mongoose.connect(MONGO_DB_CONNECTION_STRING)
.then(() => {
console.log("Connected to MongoDB...");
})
.catch(e => {
console.error("There was an error connecting to MongoDB:");
console.error(e);
});
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, authorization, token');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST');
next();
});
app.use("/researcher", researcherRoutes);
app.use("/study", studyRoutes);
app.use("/trial", trialRoutes);
app.use(express.static(path.join(__dirname, 'build')));
// app.get('/*', function (req, res) {
// res.sendFile(path.join(__dirname, 'build', 'index.html'));
// });
app.listen(PORT, () => {
console.log(`Server live on ${PORT}`)
});