giyuG
Windmill14mo ago
12 replies
giyu

Support for HTTP Browser Redirects in Windmill Functions (302 Response Handling)

Hey guys,

I'm trying to implement URL redirects through a Windmill TypeScript function.

Specifically, I want to create an endpoint that, when accessed through a browser, redirects the user to another URL (in my test case, to Google.com).

Current behavior:

When I create a TypeScript function that returns redirect information like:

typescriptCopyexport async function main() {
return {
status: 302,
headers: {
'Location': 'https://www.google.com'
}
};
}

And access it via GET request (using the sync -> GET by path method), it returns the JSON response:

jsonCopy{"status": 302, "headers": {"Location": "https://www.google.com"}}
instead of actually redirecting the browser.

I've also tried:

- Returning HTML content with meta refresh or JavaScript redirect
- Using data:URL approach with base64 encoded HTML
- Setting different Content-Type headers

However, all attempts result in the JSON being displayed rather than the browser being redirected.

My question: Is it possible to configure Windmill functions to handle proper HTTP redirects (302 status codes) when accessed directly via browser, rather than just returning JSON? Or is there a recommended pattern for implementing URL redirects in Windmill?

This functionality would be particularly useful for implementing features like:

- Email click tracking with redirects
- OAuth callback handlers
- Short URL services

Any scenario where users need to be redirected through a Windmill endpoint

Technical goal: When a user clicks a link to my Windmill endpoint, their browser should automatically redirect to the destination URL, rather than displaying the JSON response.
Was this page helpful?