From b21a942812ae93e6f34a374e63484c66a2aaa359 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 19 Apr 2024 03:22:41 +0530 Subject: [PATCH] feat: basic working scraping endpoint --- scraper/src/main.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scraper/src/main.js b/scraper/src/main.js index 0c7407a4..19d3a033 100644 --- a/scraper/src/main.js +++ b/scraper/src/main.js @@ -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}`)