From 033a53af30a72d14947bd0de01ff3e18ea83ccb3 Mon Sep 17 00:00:00 2001 From: Yanlong Wang Date: Fri, 7 Feb 2025 11:14:55 +0800 Subject: [PATCH] fix: options handling in stand-alone script --- backend/functions/package-lock.json | 9 ++++----- backend/functions/package.json | 2 +- backend/functions/src/stand-alone/crawl.ts | 17 ++++++++++++++++- backend/functions/src/stand-alone/search.ts | 17 ++++++++++++++++- thinapps-shared | 2 +- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/backend/functions/package-lock.json b/backend/functions/package-lock.json index ae431d8..f90044d 100644 --- a/backend/functions/package-lock.json +++ b/backend/functions/package-lock.json @@ -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" diff --git a/backend/functions/package.json b/backend/functions/package.json index 57a0cd0..07c2714 100644 --- a/backend/functions/package.json +++ b/backend/functions/package.json @@ -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", diff --git a/backend/functions/src/stand-alone/crawl.ts b/backend/functions/src/stand-alone/crawl.ts index 589ded2..76f9bcd 100644 --- a/backend/functions/src/stand-alone/crawl.ts +++ b/backend/functions/src/stand-alone/crawl.ts @@ -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 { diff --git a/backend/functions/src/stand-alone/search.ts b/backend/functions/src/stand-alone/search.ts index ab04d5f..59c63fc 100644 --- a/backend/functions/src/stand-alone/search.ts +++ b/backend/functions/src/stand-alone/search.ts @@ -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 { diff --git a/thinapps-shared b/thinapps-shared index 1463a18..34e1550 160000 --- a/thinapps-shared +++ b/thinapps-shared @@ -1 +1 @@ -Subproject commit 1463a18b1c039e5c0d1073998a8d6953f811406d +Subproject commit 34e1550a985fe416736420fd6e8dc2f7661b51be