feat: basic working scraping endpoint

This commit is contained in:
karishmas6
2024-04-19 03:22:41 +05:30
parent 20b40562b5
commit b21a942812

View File

@@ -1,5 +1,6 @@
import Fastify from 'fastify'
import cors from '@fastify/cors'
import scrapeData from './scraper';
const fastify = Fastify();
@@ -14,6 +15,17 @@ fastify.get('/', async (request, reply) => {
reply.send('Welcome to the Playwright Scraper API');
});
fastify.post('/scrape', async (request, reply) => {
const { url, selectors } = request.body;
try {
const response = await scrapeData(url, selectors);
reply.send(response);
} catch (error) {
reply.status(500).send({ error: error.message });
}
});
await fastify.listen(3000, (err, address) => {
if (err) throw err;
console.log(`Server listening on ${fastify.server.address().port}`)