-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (35 loc) · 1.25 KB
/
app.js
File metadata and controls
48 lines (35 loc) · 1.25 KB
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
'use strice';
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const path = require('path');
const hbs = require('express-hbs');
const config = require('./config');
const lib = require('./lib');
lib.global(config,'app');
app.use(express.static(path.join(__dirname,'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.engine('hbs', hbs.express4({
extname: '.hbs',
layoutsDir: path.join(__dirname, 'main/view/layout'),
defaultLayout: path.resolve(__dirname, 'main/view/layout.hbs'),
partialsDir: path.join(__dirname, 'main/view/partial')
}));
app.set('view engine','hbs');
app.set('views', path.join(__dirname,'main/view'));
try {
const render = require('./main/middleware/render');
const ctx = require('./main/middleware/ctx');
const errorHanlde = require('./main/middleware/error-handle');
app.use(render(require('./public/.manifest.json')));
app.use(ctx());
require('./dispatch')(app);
app.all('*', errorHanlde.notFound()); // 404
app.use(errorHanlde.serverError()); // 500
} catch (err){
console.log(err);
}
app.listen(config.port || 3000);