-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (26 loc) · 1001 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
const dotenv = require('dotenv').config();
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// Get our API routes
const api = require('./server/routes/api');
const demoApi = require('./server/routes/demo-api');
let config = {};
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
app.use('/api', api);
app.use('/demo', demoApi);
// Catch all other routes and return the index file
app.get('*', (req, res) => {
console.log(`Routing other routes to ${path.join(__dirname, 'dist/index.html')}`);
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
const port = process.env.PORT || '3000';
app.set('port', port);
app.listen(port, () => console.log(`Example app running on port ${port}`));