feat(engine): stale scrape
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import Fastify from 'fastify'
|
import Fastify from 'fastify'
|
||||||
import cors from '@fastify/cors'
|
import cors from '@fastify/cors'
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import scraper from './scraper.js';
|
import playwright from 'playwright'
|
||||||
|
|
||||||
const fastify = Fastify();
|
const fastify = Fastify();
|
||||||
|
|
||||||
@@ -12,6 +12,10 @@ const corsOptions = {
|
|||||||
|
|
||||||
await fastify.register(cors, corsOptions)
|
await fastify.register(cors, corsOptions)
|
||||||
|
|
||||||
|
fastify.get('/', async (request, reply) => {
|
||||||
|
reply.send('Welcome to the Playwright Scraper API');
|
||||||
|
});
|
||||||
|
|
||||||
fastify.get('/proxy', async (request, reply) => {
|
fastify.get('/proxy', async (request, reply) => {
|
||||||
const { url } = request.query;
|
const { url } = request.query;
|
||||||
|
|
||||||
@@ -24,20 +28,6 @@ fastify.get('/proxy', async (request, reply) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
fastify.post('/scrape', async (request, reply) => {
|
|
||||||
const { url, selectors } = request.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await scraper(url, selectors);
|
|
||||||
console.log('Scraped data:', data);
|
|
||||||
reply.send(data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error scraping:', error);
|
|
||||||
reply.status(500).send({ error: 'Failed to scrape data' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await fastify.listen(3000, (err, address) => {
|
await fastify.listen(3000, (err, address) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(`Server listening on ${fastify.server.address().port}`)
|
console.log(`Server listening on ${fastify.server.address().port}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user