mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
build: test
This commit is contained in:
parent
56f8314d29
commit
7f32a5cf9e
@ -4,6 +4,7 @@ import http from 'http';
|
|||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { OB11Response } from '../action/OB11Response';
|
import { OB11Response } from '../action/OB11Response';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
|
import cors from 'cors';
|
||||||
|
|
||||||
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
private app: Express | undefined;
|
private app: Express | undefined;
|
||||||
@ -43,21 +44,11 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
this.server?.close();
|
this.server?.close();
|
||||||
this.app = undefined;
|
this.app = undefined;
|
||||||
}
|
}
|
||||||
cors(): any {
|
|
||||||
return (req: Request, res: Response, next: any) => {
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
private initializeServer() {
|
private initializeServer() {
|
||||||
this.app = express();
|
this.app = express();
|
||||||
this.server = http.createServer(this.app);
|
this.server = http.createServer(this.app);
|
||||||
|
|
||||||
this.app.use(this.cors());
|
this.app.use(cors());
|
||||||
this.app.use(express.urlencoded({ extended: true, limit: '5000mb' }));
|
this.app.use(express.urlencoded({ extended: true, limit: '5000mb' }));
|
||||||
this.app.use((req, res, next) => {
|
this.app.use((req, res, next) => {
|
||||||
// 兼容处理没有带content-type的请求
|
// 兼容处理没有带content-type的请求
|
||||||
@ -70,7 +61,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.app.use((req, res, next) => this.authorize(this.token, req, res, next));
|
this.app.use((req, res, next) => this.authorize(this.token, req, res, next));
|
||||||
this.app.use((req, res) => this.handleRequest(req, res));
|
this.app.use((req, res) => this.handleRequest(req, res));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user