1 Star 1 Fork 2

GeekEra/GBlog-wxpush

forked from ThinkHalo/GBlog-wxpush 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
ThinkHalo 提交于 2020-06-11 10:47 . Update CORS:bug:
var express = require('express');
var app = express();
var log4js = require('log4js');
log4js.configure('./config/log4js.json');
var fs = require('fs');
var path = require('path');
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(log4js.connectLogger(log4js.getLogger("http"), { level: 'auto' }));
// 根据请求读取指定的路由文件
fs.readdirSync(path.join(__dirname, 'routes')).reverse().forEach(file => {
const filename = file.replace(/\.js$/, '');
app.use(`/${filename}`, (req, res, next) => {
const callback = require(`./routes/${filename}`);
// 允许跨域
res.header("Access-Control-Allow-Origin","*");
res.header("Access-Control-Allow-Methods","POST,GET");
callback(req, res, next);
});
})
app.set('port', process.env.PORT || 5000);
var server = app.listen(app.get('port'), function() {
console.log(`This app is running in ${app.get('port')} port`);
log4js.getLogger("startup").info('Express server listening on port ', server.address().port, " with pid ", process.pid );
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/GeekEra/GBlog-wxpush.git
git@gitee.com:GeekEra/GBlog-wxpush.git
GeekEra
GBlog-wxpush
GBlog-wxpush
master

搜索帮助