-
Notifications
You must be signed in to change notification settings - Fork 91
/
server.js
49 lines (39 loc) · 1.23 KB
/
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
40
41
42
43
44
45
46
47
48
49
import path from 'path';
import bodyParser from 'body-parser';
import express from 'express';
import compress from 'compression';
import http from 'http';
import socketIO from 'socket.io';
import config from 'config';
import * as api from './server/api/http';
import * as eventService from './server/api/service/event';
import * as uni from './server/app.js';
const app = express();
const httpServer = http.createServer(app);
const port = config.get('express.port') || 3000;
var io = socketIO(httpServer);
app.set('views', path.join(__dirname, 'server', 'views'));
app.set('view engine', 'ejs');
/**
* Server middleware
*/
app.use(compress());
app.use(require('serve-static')(path.join(__dirname, config.get('buildDirectory'))));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
/**
* API Endpoints
*/
app.get('/api/0/events', api.getEvents);
app.post('/api/0/events', api.addEvent);
app.post('/api/0/events/:id', api.editEvent);
app.delete('/api/0/events/:id', api.deleteEvent);
app.get('/favicon.ico', (req, res) => res.sendFile(path.join(__dirname, 'images', 'favicon.ico')));
/**
* Universal Application endpoint
*/
app.get('*', uni.handleRender);
eventService.liveUpdates(io);
httpServer.listen(port);