mirror of
https://github.com/intergalacticalvariable/reader.git
synced 2024-11-16 03:32:25 +08:00
feat: Add Express server with crawl endpoint
This commit is contained in:
parent
32263c7e9e
commit
57b07507d1
|
@ -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;
|
||||
|
|
13
package.json
13
package.json
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user