feat: basic working scraping endpoint
This commit is contained in:
@@ -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}`)
|
||||
|
||||
Reference in New Issue
Block a user