From 32263c7e9e84d041cc619b3b92da6195407a6a98 Mon Sep 17 00:00:00 2001 From: Harsh Gupta Date: Wed, 14 Aug 2024 19:17:23 +0530 Subject: [PATCH] feat: Add express server for crawling functionality --- backend/functions/src/server.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 backend/functions/src/server.ts diff --git a/backend/functions/src/server.ts b/backend/functions/src/server.ts new file mode 100644 index 0000000..385b41d --- /dev/null +++ b/backend/functions/src/server.ts @@ -0,0 +1,25 @@ +import express from 'express'; +import { container } from 'tsyringe'; +import { CrawlerHost } from './cloud-functions/crawler'; + +const app = express(); +const port = process.env.PORT || 3000; + +const crawlerHost = container.resolve(CrawlerHost); + +app.use(express.json()); + +app.post('/crawl', async (req, res) => { + try { + await crawlerHost.crawl(req, res); + } catch (error) { + console.error('Error during crawl:', error); + res.status(500).json({ error: 'An error occurred during the crawl' }); + } +}); + +app.listen(port, () => { + console.log(`Server is running on port ${port}`); +}); + +export default app;