代码拉取完成,页面将自动刷新
//使用express框架
const express = require("express");
//日志
const logger = require("morgan");
//图标
const favicon = require("serve-favicon");
const body_parser = require("body-parser");
//引入路由部分
const HXMRouter = require("./router/HXMRouter");
const LBRouter = require("./router/LBRouter");
const LCXRouter = require("./router/LCXRouter");
const YXXRouter = require("./router/YXXRouter");
let myExpress = express();
//配置日志
myExpress.use(logger("dev"));
//解决跨域问题
myExpress.all("*", (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
res.header(
"Access-Control-Allow-Headers",
"Content-Type,Content-Length, Authorization, Accept,X-Requested-With"
);
res.header("Access-Control-Allow-Credentials", "true");
next();
});
//设置数据请求的body编码格式
myExpress.use(body_parser.urlencoded({ extended: false }));
myExpress.use(body_parser.json());
myExpress.use(HXMRouter);
myExpress.use(LBRouter);
myExpress.use(LCXRouter);
myExpress.use(YXXRouter);
//配置静态文件
myExpress.use(express.static(__dirname + "/dist"));
myExpress.use(favicon(__dirname + "/src/images/2.jpg"));
myExpress.listen(6789, function () {
console.log("node_one,6789运行成功");
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。