-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
57 lines (48 loc) · 1.61 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
51
52
53
54
55
import * as express from 'express'
import * as path from 'path'
import * as bodyParser from 'body-parser'
import * as fs from 'fs';
import * as morgan from 'morgan';
import {productRouter} from './router'
import {uploaderRouter, multipleUploaderRouter, uploaderAPKRouter} from './router/upload'
import {bannerRouter} from './router/banner'
import {loginRouter} from './router/login'
import {webApiRouter} from './router/web';
import {alipayRouter} from "./router/alipay";
import {AdminRouter} from "./router/admin";
import {wxpay} from './router/wxpay';
const app = express();
//middleware
app.use('/', express.static(path.join(__dirname, '..', 'public'))); //静态资源存放目录
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// log all requests
app.use(morgan('common', {
skip: function (req, res) { return res.statusCode < 400 },
stream: fs.createWriteStream(path.join(__dirname, '..', 'access.log'), { flags: 'a' })
}));
//router
app.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Content-Type");
next();
});
productRouter(app);
uploaderRouter(app);
multipleUploaderRouter(app);
uploaderAPKRouter(app);
bannerRouter(app);
loginRouter(app);
webApiRouter(app);
alipayRouter(app);
AdminRouter(app);
wxpay(app);
if (process.env.NODE_ENV === 'production') {
app.listen(8000, 'localhost', () => {
console.log('app is running at pro http://localhost:8000');
});
} else {
app.listen(9527, 'localhost', () => {
console.log('app is running at dev http://localhost:9527');
});
}