diff --git a/backend/functions/src/cloud-functions/crawler.ts b/backend/functions/src/cloud-functions/crawler.ts index d50429b..ac79b1a 100644 --- a/backend/functions/src/cloud-functions/crawler.ts +++ b/backend/functions/src/cloud-functions/crawler.ts @@ -566,41 +566,11 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`; return formatted as FormattedPage; } - @CloudHTTPv2({ - name: 'crawl2', - runtime: { - memory: '4GiB', - timeoutSeconds: 300, - concurrency: 22, - }, - tags: ['Crawler'], - httpMethod: ['get', 'post'], - returnType: [String, OutputServerEventStream], - exposeRoot: true, - }) - @CloudHTTPv2({ - runtime: { - memory: '4GiB', - cpu: 4, - timeoutSeconds: 300, - concurrency: 22, - maxInstances: 455, - minInstances: 1, - }, - tags: ['Crawler'], - httpMethod: ['get', 'post'], - returnType: [String, OutputServerEventStream], - exposeRoot: true, - }) - async crawl( - @RPCReflect() rpcReflect: RPCReflection, - ctx: { - req: Request, - res: Response, - }, - crawlerOptionsHeaderOnly: CrawlerOptionsHeaderOnly, - crawlerOptionsParamsAllowed: CrawlerOptions, - ) { + async crawl(req: Request, res: Response) { + const rpcReflect = new RPCReflection(); + const ctx = { req, res }; + const crawlerOptionsHeaderOnly = CrawlerOptionsHeaderOnly.from(req.headers); + const crawlerOptionsParamsAllowed = CrawlerOptions.from(req.method === 'POST' ? req.body : req.query); const noSlashURL = ctx.req.url.slice(1); const crawlerOptions = ctx.req.method === 'GET' ? crawlerOptionsHeaderOnly : crawlerOptionsParamsAllowed; if (!noSlashURL && !crawlerOptions.url) { @@ -887,4 +857,4 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`; return this.formatSnapshot(mode, lastSnapshot, url); } -} \ No newline at end of file +} diff --git a/backend/functions/src/index.ts b/backend/functions/src/index.ts index 97c6d3f..52ca7bb 100644 --- a/backend/functions/src/index.ts +++ b/backend/functions/src/index.ts @@ -7,7 +7,12 @@ import { https } from 'firebase-functions' initializeApp(); -export const crawler = https.onRequest(CrawlerHost); +import { container } from 'tsyringe'; + +const crawlerHost = container.resolve(CrawlerHost); +export const crawler = https.onRequest(async (req, res) => { + await crawlerHost.crawl(req, res); +}); // import { loadModulesDynamically, registry } from './shared'; // import path from 'path'; // loadModulesDynamically(path.resolve(__dirname, 'cloud-functions'));