mina-api / deploy /cloudflare-worker.js
Mina
Fresh deploy without large files
25ae7fe
/**
* Cloudflare Worker - Proxy Bypass for Larooza Scraper
* Deploy this to Cloudflare Workers (100% FREE)
*
* This worker acts as a middle-man to bypass IP bans
*/
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
// Enable CORS
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
}
// Handle CORS preflight
if (request.method === 'OPTIONS') {
return new Response(null, { headers: corsHeaders })
}
// Get target URL from query parameter
const url = new URL(request.url)
const targetUrl = url.searchParams.get('url')
if (!targetUrl) {
return new Response(JSON.stringify({ error: 'Missing url parameter' }), {
status: 400,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
})
}
try {
// Fetch the target URL with realistic headers
const response = await fetch(targetUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'ar,en-US;q=0.9,en;q=0.8',
'Referer': 'https://www.google.com/',
'DNT': '1',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
},
cf: {
// Cloudflare-specific options
cacheTtl: 300, // Cache for 5 minutes
cacheEverything: true,
}
})
// Get the HTML content
const html = await response.text()
// Return with CORS headers
return new Response(html, {
status: response.status,
headers: {
...corsHeaders,
'Content-Type': 'text/html; charset=utf-8',
'Cache-Control': 'public, max-age=300',
}
})
} catch (error) {
return new Response(JSON.stringify({
error: 'Failed to fetch target URL',
message: error.message
}), {
status: 500,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
})
}
}