forked from misterkeebs/mkbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (30 loc) · 1.08 KB
/
Copy pathserver.js
File metadata and controls
36 lines (30 loc) · 1.08 KB
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
const path = require('path');
const { Client } = require('pg');
const express = require('express');
const dotenv = require('dotenv');
const cors = require('cors');
const bodyParser = require('body-parser');
const morgan = require('morgan');
dotenv.config();
const client = new Client({ connectionString: process.env.DATABASE_URL });
const app = express();
app.use(morgan('dev'));
app.use(cors());
app.use(bodyParser.json());
const ApiServer = require('./server/api-server');
const ConfirmationRoute = require('./server/confirmation-route');
const DiscordRoutes = require('./server/discord');
client.connect().then(_ => {
new DiscordRoutes(client, app).addRoutes();
new ConfirmationRoute(client, app).addRoutes();
new ApiServer(client, app).addRoutes();
app.use(express.static(path.join(__dirname, 'client', 'build')));
app.use((_, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});
const port = process.env.PORT || 3001;
app.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`Server listening on port ${port}!`);
});
});