-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 960 Bytes
/
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
// Server
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path');
const morgan = require('morgan');
const WebsocketServer = require('./socket');
const app = express();
const WSS = new WebsocketServer(5001);
module.exports.WSS = WSS;
/**
* Express API routes
*/
const TimersRouter = require('./routes/TimersRouter');
/**
* Express app middleware and settings
*/
app.use(morgan('dev'));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.raw());
app.use('/api/timers', TimersRouter);
app.use(express.static(path.resolve('client', 'dist')));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'dist', 'index.html'));
});
/**
* Creating an express server in localhost
*/
const server = app.listen(5000, () => {
console.log(`http://localhost:${server.address().port}`);
});