1 Star 0 Fork 10

xueshi0802/GiteeApi

forked from N0ts/GiteeApi 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.js 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
N0ts 提交于 2022-10-26 15:08 . 重构完成
/*
* @Author: N0ts
* @Date: 2022-10-10 14:31:20
* @Description: main
* @FilePath: /gitee-api/main.js
* @Mail:mail@n0ts.cn
*/
// 创建 express & 服务器
const express = require("express");
const app = express();
// post 请求需要
app.use(express.json());
// config
const config = require("./config/config");
// 跨域配置
app.all("*", (req, res, next) => {
try {
// google需要配置,否则报错cors error
res.setHeader("Access-Control-Allow-Credentials", "true");
// 允许的地址,http://127.0.0.1:9000这样的格式
res.setHeader("Access-Control-Allow-Origin", req.get("Origin"));
// 允许跨域请求的方法
res.setHeader(
"Access-Control-Allow-Methods",
"POST, GET, OPTIONS, DELETE, PUT"
);
// 允许跨域请求header携带哪些东西
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, If-Modified-Since"
);
} catch {
return next();
}
next();
});
// 导入路由
app.use(require("./router/router"));
// 监听端口
app.listen(config.port, function () {
console.log(`服务已启动:http://localhost:${config.port}`);
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xueshi0802/gitee-api.git
git@gitee.com:xueshi0802/gitee-api.git
xueshi0802
gitee-api
GiteeApi
master

搜索帮助