-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.js
35 lines (29 loc) · 1.06 KB
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Cloudflare Worker for Proxying Subscription URL Content
* Author: SeRaMo ( https://github.com/seramo/ )
*/
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = new URL(request.url);
// Get the 'url' parameter from query string
const userProvidedUrl = url.searchParams.get('url');
// If no URL is provided, return an error response
if (!userProvidedUrl) {
return new Response('URL parameter is required', { status: 400 });
}
try {
// Fetch the content of the user-provided URL
const response = await fetch(userProvidedUrl);
const content = await response.text();
// Return the fetched content as the response
return new Response(content, {
status: 200,
headers: { 'Content-Type': 'text/plain' }
});
} catch (error) {
// Handle any errors that occur during the fetch
return new Response('Error fetching the provided URL', { status: 500 });
}
}