-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathserver.ts
56 lines (44 loc) · 1.55 KB
/
server.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
51
52
53
54
55
56
'use strict'
import * as express from "express";
import * as bodyParser from "body-parser";
import errorHandler = require("errorhandler");
import methodOverride = require("method-override");
import * as cookieParser from 'cookie-parser';
import {config} from './env'
import * as index from "./server/routes/index";
import * as cookbook from "./server/routes/cookbook";
import * as cookbookDetail from './server/routes/cookbookDetail';
var app = express();
// Configuration
var env = config.NODE_ENV || 'development';
if (env === 'development') {
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var WebpackConfig = require('./webpack.dev.config');
app.use(errorHandler());
app.use(webpackDevMiddleware(webpack(WebpackConfig), {
publicPath: '/__build__/',
stats: {
colors: true
}
}));
app.set('views',__dirname + '/server/views/dev');
}else{
app.set('views',config.PATH_BUILD);
}
app.set('view engine', 'html');
app.engine('.html', require('ejs').__express)
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(cookieParser());
app.use(express.static(__dirname));
// Routes
app.get('/', index.index);
app.get('/cookbook', index.index);
app.get('/cookbook/:id', cookbook.index);
app.get('/cookbookDetail/:id', cookbookDetail.index);
app.listen(config.PORT, function(){
console.log("Demo Express server listening on port %d in %s mode", config.PORT, config.NODE_ENV);
});
export var App = app;