-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
39 lines (32 loc) · 1.44 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
36
37
38
39
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
import handleRedirect from './redirect.js';
// Export a default object containing event handlers
export default {
// The fetch handler is invoked when this worker receives a HTTP(S) request
// and should return a Response (optionally wrapped in a Promise)
async fetch(request, env, ctx) {
// You'll find it helpful to parse the request.url string into a URL object. Learn more at https://developer.mozilla.org/en-US/docs/Web/API/URL
const url = new URL(request.url);
try {
return handleRedirect.fetch(request, env, ctx)
} catch (err) {
Response.redirect("https://aaanh.com")
}
// return new Response(
// `Try making requests to:
// <ul>
// <li><code><a href="/redirect?redirectUrl=https://example.com/">/redirect?redirectUrl=https://example.com/</a></code>,</li>
// <li><code><a href="/proxy?modify&proxyUrl=https://example.com/">/proxy?modify&proxyUrl=https://example.com/</a></code>, or</li>
// <li><code><a href="/api/todos">/api/todos</a></code></li>`,
// { headers: { "Content-Type": "text/html" } }
// );
},
};