From 48b36e974c0de373bc1da1ab262deb550438d465 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 16 Apr 2024 23:49:05 +0530 Subject: [PATCH] feat: proxy route --- scraper/src/main.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scraper/src/main.js b/scraper/src/main.js index c5e93417..2829715e 100644 --- a/scraper/src/main.js +++ b/scraper/src/main.js @@ -9,6 +9,18 @@ const corsOptions = { } fastify.register(require('@fastify/cors'), corsOptions) +fastify.get('/proxy', async (request, reply) => { + const { url } = request.query; + + try { + const response = await fetch(url); + const html = await response.text(); + reply.type('text/html').send(html); + } catch (error) { + reply.status(500).send(`Error fetching website: ${error.message}`); + } +}); + fastify.post('/scrape', async (request, reply) => { const { url, selectors } = request.body;