Merge pull request #197 from jinyu2022/main

添加CORS允许跨源访问
This commit is contained in:
手瓜一十雪 2024-04-17 15:22:38 +08:00 committed by GitHub
commit 1d47f89011
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 9 deletions

21
package-lock.json generated
View File

@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"compressing": "^1.10.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"file-type": "^19.0.0",
"fluent-ffmpeg": "^2.1.2",
@ -2662,6 +2663,18 @@
"resolved": "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/create-require": {
"version": "1.1.1",
"resolved": "https://mirrors.cloud.tencent.com/npm/create-require/-/create-require-1.1.1.tgz",
@ -5078,6 +5091,14 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/object-inspect": {
"version": "1.13.1",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz",

View File

@ -15,6 +15,7 @@
"license": "ISC",
"dependencies": {
"compressing": "^1.10.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"file-type": "^19.0.0",
"fluent-ffmpeg": "^2.1.2",

View File

@ -1,5 +1,6 @@
import express, { Express, Request, Response } from "express";
import http from "http";
import cors from 'cors';
import { log } from "../utils/log";
import { getConfigUtil } from "../config";
import { llonebotError } from "../data";
@ -13,6 +14,8 @@ export abstract class HttpServerBase {
constructor() {
this.expressAPP = express();
// 添加 CORS 中间件
this.expressAPP.use(cors());
this.expressAPP.use(express.urlencoded({ extended: true, limit: "5000mb" }));
this.expressAPP.use((req, res, next) => {
// 兼容处理没有带content-type的请求