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

event.url is not set when --https flag is used #4362

Closed
DrMagPie opened this issue Mar 16, 2022 · 5 comments · Fixed by #4364
Closed

event.url is not set when --https flag is used #4362

DrMagPie opened this issue Mar 16, 2022 · 5 comments · Fixed by #4364
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Milestone

Comments

@DrMagPie
Copy link

DrMagPie commented Mar 16, 2022

Describe the bug

when using svelte-kit dev command with --https flag event.url is not configured properly. Please see following output.

URL {
  href: 'https://undefined/',
  origin: 'https://undefined',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'undefined',
  hostname: 'undefined',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

if --https flag is not used output looks like this

URL {
  href: 'http://localhost:3000/',
  origin: 'http://localhost:3000',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'localhost:3000',
  hostname: 'localhost',
  port: '3000',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Reproduction

to see the issue use following hooks.ts file

import type { Handle } from "@sveltejs/kit";
export const handle: Handle = async ({ event, resolve }) => {
  console.log(event.url)
  const response = await resolve(event);
  return response;
};

then just start dev server and visit any page
yarn dev --https

Logs

❯ yarn dev 
yarn run v1.22.17
warning package.json: No license field
$ svelte-kit dev

  SvelteKit v1.0.0-next.299

  local:   http://localhost:3000
  network: not exposed

  Use --host to expose server to other devices on this network


URL {
  href: 'http://localhost:3000/',
  origin: 'http://localhost:3000',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'localhost:3000',
  hostname: 'localhost',
  port: '3000',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

❯ yarn dev --https
yarn run v1.22.17
warning package.json: No license field
$ svelte-kit dev --https

  SvelteKit v1.0.0-next.299

  local:   https://localhost:3000
  network: not exposed

  Use --host to expose server to other devices on this network


URL {
  href: 'https://undefined/',
  origin: 'https://undefined',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'undefined',
  hostname: 'undefined',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

System Info

❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
Need to install the following packages:
  envinfo
Ok to proceed? (y) y

  System:
    OS: macOS 12.0.1
    CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
    Memory: 478.73 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 17.4.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.3.1 - /usr/local/bin/npm
  Browsers:
    Firefox Developer Edition: 99.0
    Safari: 15.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.33 
    @sveltejs/kit: ^1.0.0-next.299 => 1.0.0-next.299 
    svelte: ^3.46.0 => 3.46.4

Severity

annoyance

Additional Information

No response

@Conduitry Conduitry added the bug Something isn't working label Mar 16, 2022
@Conduitry
Copy link
Member

Conduitry commented Mar 16, 2022

When using dev --https, req.headers.host doesn't appear to be defined at

const base = `${vite.config.server.https ? 'https' : 'http'}://${req.headers.host}`;

I'm not sure whether this should be considered a bug in Vite, or whether we should just use something like req.headers[':authority'] || req.headers.host here instead, or something else.

@benmccann
Copy link
Member

benmccann commented Mar 16, 2022

If I visit https://news.ycombinator.com/ I see a Host header in the Chrome developer tools, but I don't see one if I visit https://localhost:3000/. I'm guessing it's because localhost is using h2 and HN is using http/1.1

@benmccann benmccann added the p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. label Mar 16, 2022
@DrMagPie
Copy link
Author

DrMagPie commented Mar 16, 2022

Same problem appears using local network IP, not sure if it is related to localhost and H2.

image

P.S. sorry for duplication, did not find the #4319 :(

@bitcrshr
Copy link

bitcrshr commented Jun 28, 2022

Hey folks!

I haven't experienced this issue while running locally with npm run dev, so it looks like that's been nicely fixed. However, I run into it with npm run build followed by npm run preview -- --https. I get the same issue when my project is deployed to Vercel.

To be clear, it's the exact same story, where host and hostname are undefined on the url object. Any ideas?

Thanks!

@xmlking
Copy link

xmlking commented Dec 31, 2022

I also face same issue after enabling https with https://github.com/liuweiGL/vite-plugin-mkcert
and npm run build followed by npm run preview -- --https

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants