-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
36 lines (32 loc) · 1.12 KB
/
index.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
import * as express from 'express';
import * as handlebars from 'express-handlebars';
import * as bodyParser from 'body-parser';
import * as cookieParser from 'cookie-parser';
import * as session from 'express-session';
import { HomeController } from './controllers/home.controller';
import { Router } from './router';
import { Config } from './config';
var config = new Config();
var homeController = new HomeController();
var app = express();
app.use(express.static('public'));
// use router
app.use('/', new Router().router);
// use cookie and session
app.use(cookieParser(config.session_secret));
app.use(session({
secret: config.session_secret,
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}));
//register view engine
app.engine('html', handlebars.create({ defaultLayout: "main", extname: '.html' }).engine);
app.set('view engine', 'html');
// bodyParser
app.use(bodyParser.json({ limit: '1mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '1mb' }));
app.get('/', homeController.index);
app.listen(config.port, function () {
console.log(`Example app listening on port ${config.port}!`);
});