forked from windmill-labs/windmill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d915f6b
commit 38addd3
Showing
1 changed file
with
32 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
//this is purely for cloudflare pages redirection purposes | ||
|
||
export async function onRequest(context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context | ||
|
||
try { | ||
const url = new URL(request.url) | ||
url.hostname = "app.windmill.dev" | ||
const res = await fetch(url.toString(), { method: request.method, body: request.body, headers: request.headers, redirect: 'manual' }) | ||
const newResponse = new Response(res.body, res); | ||
newResponse.headers.set('set-cookie', newResponse.headers.get('set-cookie')?.replace('Domain=windmill.dev;', '') ?? '') | ||
return newResponse | ||
} catch (e) { | ||
return new Response(e.message, { status: 500 }) | ||
} | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
|
||
try { | ||
const url = new URL(request.url); | ||
url.hostname = "app.windmill.dev"; | ||
const res = await fetch(url.toString(), { | ||
method: request.method, | ||
body: request.body, | ||
headers: request.headers, | ||
redirect: "manual", | ||
}); | ||
const newResponse = new Response(res.body, res); | ||
newResponse.headers.set( | ||
"set-cookie", | ||
"token" + | ||
newResponse.headers | ||
.get("set-cookie") | ||
?.replace("Domain=windmill.dev;", "") | ||
?.split("token") | ||
.pop() ?? "" | ||
); | ||
return newResponse; | ||
} catch (e) { | ||
return new Response(e.message, { status: 500 }); | ||
} | ||
} |