-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.ts
71 lines (59 loc) · 1.92 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict'
import * as express from "express";
import * as bodyParser from "body-parser";
import * as errorHandler from "errorhandler";
import * as methodOverride from "method-override";
import * as cookieParser from "cookie-parser";
import * as queryString from 'querystring';
import {config} from './env'
//webapp
import * as index from './server/webapp/routes/index'
var app = express();
app.use(errorHandler());
// 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(webpackDevMiddleware(webpack(WebpackConfig), {
publicPath: '/demo/',
stats: {
colors: true
}
}));
app.set('views',__dirname + '/server/views/dev');
}else{
app.set('views',__dirname + '/public/demo');
}
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+'/public'));
// Routes
app.get('/demo/index',index.index);
app.get('/demo/picker',index.index);
app.get('/demo/toast',index.index);
app.get('/demo/alert',index.index);
app.get('/demo/preloader',index.index);
app.get('/demo/indicator',index.index);
app.get('/demo/actions',index.index);
app.get('/demo/pullToRefresh',index.index);
app.get('/demo/infiniteScroll',index.index);
app.get('/demo/popup',index.index);
app.get('/demo/calendar',index.index);
app.get('/demo/datetime',index.index);
//错误处理
app.get('/*',function(req,res){
res.writeHead(301,{
'Location':'/demo/index'
});
res.end();
});
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;