fix: options handling in stand-alone script

This commit is contained in:
Yanlong Wang 2025-02-07 11:14:55 +08:00
parent 0f36fe81a6
commit 033a53af30
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
5 changed files with 38 additions and 9 deletions

View File

@ -16,7 +16,7 @@
"axios": "^1.3.3",
"bcrypt": "^5.1.0",
"busboy": "^1.6.0",
"civkit": "^0.8.2-03243fe",
"civkit": "^0.8.3-3e69606",
"core-js": "^3.37.1",
"cors": "^2.8.5",
"dayjs": "^1.11.9",
@ -3979,10 +3979,9 @@
}
},
"node_modules/civkit": {
"version": "0.8.2-03243fe",
"resolved": "https://registry.npmjs.org/civkit/-/civkit-0.8.2-03243fe.tgz",
"integrity": "sha512-hoTxGeGdD27iOCDi51cVY0PHlRN3OSC640QRJ1YSmD42o+LP7mZtbdy8dN7j/FSkPP/5yLuB2ch9BMSOp54POQ==",
"license": "AGPL",
"version": "0.8.3-3e69606",
"resolved": "https://registry.npmjs.org/civkit/-/civkit-0.8.3-3e69606.tgz",
"integrity": "sha512-niV5U11ySIiVNSnGpW49KJlExmIiuQQfnyQEXeYuKCE+B+wkqYCBG+3tlY3E882tmPkaQQKpDlF/yTeqEU2q2Q==",
"dependencies": {
"lodash": "^4.17.21",
"tslib": "^2.5.0"

View File

@ -36,7 +36,7 @@
"axios": "^1.3.3",
"bcrypt": "^5.1.0",
"busboy": "^1.6.0",
"civkit": "^0.8.2-03243fe",
"civkit": "^0.8.3-3e69606",
"core-js": "^3.37.1",
"cors": "^2.8.5",
"dayjs": "^1.11.9",

View File

@ -98,6 +98,16 @@ export class CrawlStandAloneServer extends ExpressServer {
};
}
makeIgnoreOPTIONSMiddleware() {
return (req: Request, res: Response, next: NextFunction) => {
if (req.method === 'OPTIONS') {
return res.status(200).end();
}
return next();
};
}
override listen(port: number) {
const r = super.listen(port);
if (this.httpAlternativeServer) {
@ -132,7 +142,12 @@ export class CrawlStandAloneServer extends ExpressServer {
res.end(JSON.stringify(content));
});
this.expressRootRouter.use('/', ...this.registry.expressMiddlewares, this.makeAssetsServingController(), this.registry.makeShimController('crawl'));
this.expressRootRouter.use('/',
...this.registry.expressMiddlewares,
this.makeAssetsServingController(),
this.makeIgnoreOPTIONSMiddleware(),
this.registry.makeShimController('crawl')
);
}
protected override featureSelect(): void {

View File

@ -98,6 +98,16 @@ export class SearchStandAloneServer extends ExpressServer {
};
}
makeIgnoreOPTIONSMiddleware() {
return (req: Request, res: Response, next: NextFunction) => {
if (req.method === 'OPTIONS') {
return res.status(200).end();
}
return next();
};
}
override listen(port: number) {
const r = super.listen(port);
if (this.httpAlternativeServer) {
@ -132,7 +142,12 @@ export class SearchStandAloneServer extends ExpressServer {
res.end(JSON.stringify(content));
});
this.expressRootRouter.use('/', ...this.registry.expressMiddlewares, this.makeAssetsServingController(), this.registry.makeShimController('search'));
this.expressRootRouter.use('/',
...this.registry.expressMiddlewares,
this.makeIgnoreOPTIONSMiddleware(),
this.makeAssetsServingController(),
this.registry.makeShimController('search')
);
}
protected override featureSelect(): void {

@ -1 +1 @@
Subproject commit 1463a18b1c039e5c0d1073998a8d6953f811406d
Subproject commit 34e1550a985fe416736420fd6e8dc2f7661b51be