-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
40 lines (24 loc) · 1013 Bytes
/
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
const express = require('express');
const db = require('./sequelizeSettings');
const app = require('./router.js');
const isEnvironmentSet = require('./utils/environmentVariablesCheck.js');
if (!isEnvironmentSet()){
process.exit(1);
}
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const swaggerDocument = YAML.load('./API_reference.yaml');
app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
//Test DB
db.authenticate()
.then(() => console.log('Database connected'))
.catch(err => console.log('Error: ' + err));
//START OF THE REQUIRED CODE TO MAKE THE DEPLOY WORK
const path = require("path");
app.use(express.static(path.join(__dirname, "thespoon", "build")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "thespoon", "build", "index.html"));
});
//END OF THE REQUIRED CODE TO MAKE THE DEPLOY WORK
const port = process.env.PORT || 80;
app.listen(port, () => console.log('Server started on port ' + port));