feat: Add Express server with crawl endpoint

This commit is contained in:
Harsh Gupta (aider) 2024-08-14 19:17:25 +05:30
parent 32263c7e9e
commit 57b07507d1
2 changed files with 35 additions and 3 deletions

View File

@ -23,3 +23,28 @@ app.listen(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' });
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
export default app;

View File

@ -4,12 +4,19 @@
"description": "### Prerequisite - Node v18 (The build fails for Node version >18) - Yarn - Firebase CLI (`npm install -g firebase-tools`)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/server.ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"firebase-tools": "^12.4.2",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"@types/express": "^4.17.17",
"ts-node": "^10.9.1"
},
"dependencies": {
"express": "^4.17.1",
"tsyringe": "^4.7.0"
}
}
}