-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (32 loc) · 1021 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
import config from './config';
import apiRouter from './api';
import express from 'express';
import path from 'path';
import sassMiddleware from 'node-sass-middleware';
import bodyParser from 'body-parser';
const server = express();
server.use(
sassMiddleware({
src: path.join(__dirname, 'sass'),
dest: path.join(__dirname, 'public'),
})
);
// Parse JSON in request bodies
server.use(bodyParser.json());
server.set('view engine', 'ejs');
import serverRender from './serverRender';
server.get(['/', '/contest/:contestId'], (request, response) => {
serverRender(request.params.contestId)
.then(({ initialMarkup, initialData }) => {
response.render('index', { initialMarkup, initialData });
})
.catch((error) => {
console.error(error);
response.status(404).send('Bad Request');
});
});
server.use(express.static('public'));
server.use('/api', apiRouter);
server.listen(config.port, config.host, () => {
console.log(`Express listening on port: ${config.port}`);
});