Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treaty does not pass fetch props to fetcher when using URL Endpoint #590

Open
hranum opened this issue Apr 4, 2024 · 0 comments
Open

treaty does not pass fetch props to fetcher when using URL Endpoint #590

hranum opened this issue Apr 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hranum
Copy link

hranum commented Apr 4, 2024

What version of Elysia.JS is running?

1.0.11

What platform is your computer?

Linux 6.8.2-arch2-1 x86_64 unknown

What steps can reproduce the bug?

Server:

import { Server } from "bun";
import Elysia from "elysia";
const app = new Elysia().get("/", ({ set }) => (set.redirect = "https://google.com"));
app.listen(3000);

Some other place:

export const treatyApp = treaty<App>("http://localhost:3000", {
    fetcher: (url, options) => {
        console.log(options); // Should output the options we pass
        return fetch(url, options);
    },
});

const res = await treatyApp.index.get({ fetch: { redirect: "manual" } });

console.log(res.data);
console.log(res.headers);

What is the expected behavior?

Given the signature of the treaty function, I'm expecting to be able to pass options to fetch, or a custom fetch function.

(property) get: (options?: {
    headers?: Record<string, unknown> | undefined;
    query?: Record<string, unknown> | undefined;
    fetch?: RequestInit | undefined;
} | undefined) => Promise<TreatyResponse<...>>

The expected output should be:

{ method: 'GET', headers: {}, redirect: 'manual' }

In the example above, with legacy treaty, I could stop a redirect, or pass other options to the fetch funciton.

What do you see instead?

The log output is for options is: { method: 'GET', headers: {} } and the data is the html document of the redirect location. I.e the redirect happens.

I'm using the "fetcher" option to treaty to demonstrate, it is the same error when using the env default.

Additional information

Does not seem to be an issue if passing the Elysia instance instead of the Endpoint URL.

Globally changing redirect or other options, like this does work, but I have to be able to control it per request as with legacy:

const treatyApp = treaty<App>("http://localhost:3000", {
    fetch: {
        redirect: "manual",
    },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant