1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**
- * express Main
- */
- console.time("服务启动用时")
- const u_config = require('../config/systemConfig');
- const express = require('express');
- const APP = express();
- //系统初始化入口
- const startServer = require('./server/InitServer.js')
- /**日志框架*/
- var logger = require('morgan');
- APP.use(logger('dev'));
- /**解析post body各种格式的请求体*/
- let bodyParser = require('body-parser');
- // 解析 application/json
- APP.use(bodyParser.json());
- // 解析 url编码
- APP.use(bodyParser.urlencoded({ extended: true }));
- /**设置跨域访问 方式1*/
- APP.all('*', function (req, res, next) {
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
- res.header("X-Powered-By", ' 3.2.1')
- // res.header("Content-Type", "application/json;charset=utf-8");
- res.header("Cache-Control", "no-cache, no-store, must-revalidate");
- res.header("Pragma", "no-cache");
- res.header("Expires", 0);
- next();
- });
- /**设置跨域访问 方式2 */
- const cors = require('cors');
- APP.use(cors())
- /**服务器端禁用缓存 */
- APP.disable('etag');
- /**异常处理 */
- process.on('uncaughtException', function (err) {
- console.log("uninpho错误提示:" + err);
- console.log("uninpho错误提示:" + err.stack)
- });
- //服务初始化入口
- startServer(APP);
- /**启动服务-端口-IP */
- APP.listen(u_config.base.PORT, u_config.base.IP, function () {
- console.log('\x1B[34m%s\x1B[0m', `服务地址: http://${ u_config.base.IP}:${u_config.base.PORT}/`);
- console.timeEnd("服务启动用时");
- });
|