gornostay25 / svelte-adapter-bun

A SvelteKit adapter for Bun
MIT License
537 stars 34 forks source link

Url wrong protocol? #62

Open m1212e opened 4 months ago

m1212e commented 4 months ago

Hi, no matter if I configure ORIGIN, PROTOCOL_HEADER or HOST_HEADER my load function gets the URL as HTTP not HTTPS.

My load function:

export const load: LayoutServerLoad = async ({ url, cookies, request }) => {
    console.log('url', url.toString());
    console.log('headers', request.headers);
};

My envs:

    environment:
      - HOST_HEADER=x-forwarded-host
      - PROTOCOL_HEADER=x-forwarded-proto
      - ORIGIN=https://staging.app.my.domain.de

My console output on request:

 url http://staging.app.my.domain.de/registration
 headers Headers {
   "host": "staging.app.my.domain.de",
   "user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0",
   "accept": "*/*",
   "accept-encoding": "gzip, deflate, br, zstd",
   "accept-language": "de-DE,en;q=0.5",
   "cache-control": "no-cache",
   "cookie": "paraglide:lang=en",
   "dnt": "1",
   "pragma": "no-cache",
   "referer": "https://staging.app.my.domain.de/",
   "sec-fetch-dest": "empty",
   "sec-fetch-mode": "cors",
   "te": "trailers",
   "priority": "u=4",
   "sec-fetch-site": "same-origin",
   "sec-gpc": "1",
   "x-forwarded-for": "172.23.0.1",
   "x-forwarded-host": "staging.app.my.domain.de",
   "x-forwarded-port": "443",
   "x-forwarded-proto": "https",
   "x-forwarded-server": "f5c2bc4386a1",
   "x-real-ip": "172.23.0.1",
 }

Whats the problem here?

m1212e commented 4 months ago

Also my adapter is configured like this:

adapter: adapter({
            dynamic_origin: true,
        }),
ckiee commented 1 month ago

update: probably fixed by https://github.com/gornostay25/svelte-adapter-bun/commit/8140529

I ended up just doing

const requestFixupHandle: Handle = async ({ event, resolve }) => {
    // yes this is also still necessary . silly shit. this one is for the redirect url
    if (env.IS_HTTPS == "1")
        event.url = new URL(event.url.toString().replace(/^http:/, "https:"))

    // authjs is a naughty beast and uses this other url (event.request.url)
    // which is Request#url which is readonly.. use some hax
    event.request = new Request(event.url, {
        method: event.request.method,
        headers: event.request.headers,
        body: event.request.body,
        referrer: event.request.referrer,
        referrerPolicy: event.request.referrerPolicy,
        mode: event.request.mode,
        credentials: event.request.credentials,
        cache: event.request.cache,
        redirect: event.request.redirect,
        integrity: event.request.integrity,
        //@ts-ignore
        duplex: event.request.duplex
    });

    return resolve(event);
};

hope it helps you proceed!