-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.ts
50 lines (41 loc) · 1.43 KB
/
app.ts
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
"use strict";
import express from 'express';
import path from 'path';
import favicon from 'serve-favicon';
import logger from 'morgan';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import { HttpError } from './models/http_error'
import { index } from './routes/index';
import { users } from './routes/users';
export default class App {
public app: express.Application;
constructor() {
this.app = express();
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
this.app.use(logger('dev'));
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: false }));
this.app.use(cookieParser());
this.app.use(express.static(path.join(__dirname, 'public')));
this.app.use('/', index);
this.app.use('/users', users);
// catch 404 and forward to error handler
this.app.use(function (req, res, next) {
var err = new HttpError('Not Found', 404);
next(err);
});
// error handler
this.app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.sendFile('error.html', {
root: (<any>global).appRoot + '/public/'
});
});
}
}