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}`)