forked from urfu-2015/webdev-tasks-5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
77 lines (65 loc) · 1.89 KB
/
app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const express = require('express');
const app = express();
const path = require('path');
const hbs = require('hbs');
// const config = require('config');
const bodyParser = require('body-parser');
const morgan = require('morgan');
// const errorHandler = require('error-handler');
const viewsDir = path.join(__dirname, 'server/bundles');
const publicDir = path.join(__dirname, 'static');
app
.set('port', process.env.PORT || 3000)
.set('views', viewsDir)
.set('view engine', 'hbs')
.use(morgan('dev'))
.use(express.static(publicDir))
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
/* eslint max-params: [2, 4] */
.use((err, req, res, next) => {
console.log(err);
next();
})
.use((req, res, next) => {
req.commonData = {
meta: {
charset: 'utf-8',
description: 'ToDo service for all of your tasks'
},
page: {
title: 'TODO-хи'
},
isProd: process.env.NODE_ENV === 'production'
};
next();
});
require('./server/routes')(app);
hbs.registerPartials(path.join(__dirname, 'server/blocks'));
/*app
.get('/', (req, res) => {
res.send('Hello');
});
app.get('*', res => res.sendStatus(404));*/
app.listen(app.get('port'),
() => console.log(`Listening on port ${app.get('port')}`));
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
proxy: {
'*': 'http://localhost:3000'
},
stats: {
colors: true
}
}).listen(3001, 'localhost', function (err) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3001');
});