-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (31 loc) · 961 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
import config from './config';
import express from 'express';
import apiRouter from './api';
import util, { error } from 'util';
import sassMiddleware from 'node-sass-middleware';
import path from 'path';
import serverRender from './serverRender';
import bodyParser from 'body-parser';
const app = express();
app.use(sassMiddleware({
src: path.join(__dirname, 'sass'),
dest: path.join(__dirname , 'public')
}));
app.set('view engine' , 'ejs');
app.use(bodyParser.json());
app.get(['/' , '/contest/:contestId'], (req , res) => {
serverRender(req.params.contestId)
.then(({initialMarkup , initialData}) => {
res.render('index' , {
initialMarkup,
initialData
});
})
.catch( err => {
console.error(err.message || err);
res.send('Error in Server Render')
});
});
app.use(express.static('public'));
app.use('/api' , apiRouter);
app.listen(config.port ,config.host, () => util.log('Express is listening on port ' , config.port));