From 39a446f5e712e00fd1b05f1c71c93724034c2eba Mon Sep 17 00:00:00 2001 From: "yanlong.wang" Date: Thu, 25 Apr 2024 15:43:17 +0800 Subject: [PATCH] fix: root content --- .../functions/src/cloud-functions/crawler.ts | 21 +++++++++++++------ thinapps-shared | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/functions/src/cloud-functions/crawler.ts b/backend/functions/src/cloud-functions/crawler.ts index f3579ad..4123f58 100644 --- a/backend/functions/src/cloud-functions/crawler.ts +++ b/backend/functions/src/cloud-functions/crawler.ts @@ -263,6 +263,7 @@ ${this.content} tags: ['Crawler'], httpMethod: ['get', 'post'], returnType: [String, OutputServerEventStream], + exposeRoot: true, }) async crawl( @RPCReflect() rpcReflect: RPCReflection, @@ -272,21 +273,29 @@ ${this.content} }, ) { const noSlashURL = ctx.req.url.slice(1); + if (!noSlashURL) { + return assignTransferProtocolMeta(`[Usage] https://r.jina.ai/YOUR_URL +[Homepage] https://jina.ai/reader +[Source code] https://github.com/jina-ai/reader +`, + { contentType: 'text/plain', envelope: null } + ); + } let urlToCrawl; try { urlToCrawl = new URL(normalizeUrl(noSlashURL.trim(), { stripWWW: false, removeTrailingSlash: false, removeSingleSlash: false })); - if (urlToCrawl.protocol !== 'http:' && urlToCrawl.protocol !== 'https:') { - throw new ParamValidationError({ - message: `Invalid protocol ${urlToCrawl.protocol}`, - path: 'url' - }); - } } catch (err) { throw new ParamValidationError({ message: `${err}`, path: 'url' }); } + if (urlToCrawl.protocol !== 'http:' && urlToCrawl.protocol !== 'https:') { + throw new ParamValidationError({ + message: `Invalid protocol ${urlToCrawl.protocol}`, + path: 'url' + }); + } const customMode = ctx.req.get('x-respond-with') || 'markdown'; const noCache = Boolean(ctx.req.get('x-no-cache')); diff --git a/thinapps-shared b/thinapps-shared index 64157bc..1346b51 160000 --- a/thinapps-shared +++ b/thinapps-shared @@ -1 +1 @@ -Subproject commit 64157bc57ef9ce2cec69f37b5f55fccb71742b6f +Subproject commit 1346b514f3a8d183922bf9257a7f52446a581ac0