mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 14:41:23 +08:00
improve
This commit is contained in:
@@ -6,17 +6,18 @@ const app = express();
|
||||
let cache = apicache.middleware;
|
||||
|
||||
// 跨域设置
|
||||
// app.all('*', function (req, res, next) {
|
||||
// if (req.path !== '/' && !req.path.includes('.')) {
|
||||
// res.header('Access-Control-Allow-Credentials', true)
|
||||
// // 这里获取 origin 请求头 而不是用 *
|
||||
// res.header('Access-Control-Allow-Origin', req.headers['origin'] || '*')
|
||||
// res.header('Access-Control-Allow-Headers', 'X-Requested-With')
|
||||
// res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
|
||||
// res.header('Content-Type', 'application/json;charset=utf-8')
|
||||
// }
|
||||
// next()
|
||||
// })
|
||||
app.all("*", function(req, res, next) {
|
||||
if (req.path !== "/" && !req.path.includes(".")) {
|
||||
res.header("Access-Control-Allow-Credentials", true);
|
||||
// 这里获取 origin 请求头 而不是用 *
|
||||
res.header("Access-Control-Allow-Origin", req.headers["origin"] || "*");
|
||||
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
||||
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
|
||||
res.header("Content-Type", "application/json;charset=utf-8");
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
const onlyStatus200 = (req, res) => res.statusCode === 200;
|
||||
|
||||
app.use(cache("2 minutes", onlyStatus200));
|
||||
|
||||
Reference in New Issue
Block a user