diff --git a/backend/functions/src/server.ts b/backend/functions/src/server.ts index 8d9747b..8e583ec 100644 --- a/backend/functions/src/server.ts +++ b/backend/functions/src/server.ts @@ -1,3 +1,4 @@ +import "reflect-metadata" import express from 'express'; import { container } from 'tsyringe'; import { CrawlerHost } from './cloud-functions/crawler'; @@ -5,12 +6,17 @@ import { CrawlerHost } from './cloud-functions/crawler'; const app = express(); const port = process.env.PORT || 3000; +container.registerSingleton(CrawlerHost); + const crawlerHost = container.resolve(CrawlerHost); app.use(express.json()); -app.post('/crawl', async (req, res) => { +// Example curl for /crawl: +// curl -X GET "http://localhost:3000/https://example.com" +app.get('/:url(*)', async (req, res) => { try { + const url = req.params.url; await crawlerHost.crawl(req, res); } catch (error) { console.error('Error during crawl:', error); @@ -18,33 +24,14 @@ app.post('/crawl', async (req, res) => { } }); -app.listen(port, () => { - console.log(`Server is running on port ${port}`); -}); - -export default app; -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' }); - } +// Example curl for /hello: +// curl -X GET "http://localhost:3000/hello" +app.get('/hello', (req, res) => { + res.json({ message: 'Hello, World!' }); }); app.listen(port, () => { console.log(`Server is running on port ${port}`); }); -export default app; +export default app; \ No newline at end of file