mirror of
https://github.com/intergalacticalvariable/reader.git
synced 2024-11-16 11:42:32 +08:00
feat: Add express server for crawling functionality
This commit is contained in:
parent
1d8b3eae0d
commit
32263c7e9e
25
backend/functions/src/server.ts
Normal file
25
backend/functions/src/server.ts
Normal file
|
@ -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;
|
Loading…
Reference in New Issue
Block a user