forked from pandemicprep/pandemicprep
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
43 lines (34 loc) · 1.1 KB
/
index.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
// This is the Web Server
const express = require('express');
const server = express();
//set up dotenv
require('dotenv').config();
// create logs for everything
const morgan = require('morgan');
server.use(morgan('dev'));
// handle application/json requests
const bodyParser = require('body-parser');
server.use(bodyParser.json());
// here's our static files
const path = require('path');
server.use(express.static(path.join(__dirname, 'build')));
// here's our API
server.use('/api', require('./routes'));
// by default serve up the react app if we don't recognize the route
server.use((req, res, next) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'))
});
// bring in the DB connection
const { client } = require('./db/client');
// connect to the server
const PORT = process.env.PORT || 5000;
// const PORT = process.env.DATABASE_URL || 5000;
server.listen(PORT, async () => {
console.log(`Server is running on ${ PORT }!`);
try {
await client.connect();
console.log('Database is open for business!');
} catch (error) {
console.error("Database is closed for repairs!\n", error);
}
});