-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (31 loc) · 991 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
37
38
39
40
41
42
43
import config from './config';
import express from 'express';
import fs from 'fs';
import apiRouter from './api';
import sassMiddleware from 'node-sass-middleware';
import path from 'path';
import serverRender from './serverRender';
const server = express();
server.set('view engine', 'ejs');
server.use(sassMiddleware({
src: path.join(__dirname, 'sass'),
dest: path.join(__dirname, 'public')
}));
server.get(['/', '/contest/:contestId'], (req, resp) => {
serverRender(req.params.contestId)
.then(({initialMarkup, initialData}) => {
resp.render('index', {
initialMarkup,
initialData
});
})
.catch(error => {
console.log(error);
resp.status(404).send('Bad request ' + error.toString());
});
});
server.use(express.static('public'));
server.use('/api', apiRouter);
server.listen(config.port, config.host, () => {
console.log('express is listening on port: ' + config.port);
});