12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /**
- * express Main
- */
- console.time("服务启动用时")
- //引框架
- //app作为ep()返回值
- const express = require('express');
- const APP = express();
- //系统初始化入口
- const startServer = require('./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, express);
- /**启动服务-端口-IP */
- APP.listen(u_config.base.PORT, function () {
- console.log('\x1B[34m%s\x1B[0m', `服务地址: http://${u_config.base.IP}:${u_config.base.PORT}/`);
- console.timeEnd("服务启动用时");
- });
|