Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SvelteKit - get protocol

Tags:

sveltekit

Is it possible in SvelteKit to get protocol of current page (HTTP or HTTPS)?

Something like:

import {page} from '$app/stores';

console.log($page.protocol);

So far, I only see:

{
  host: 'localhost:3000',
  path: '/projektDetalji',
  query: URLSearchParams { 'id' => '1' },
  params: {}
}
like image 239
Hrvoje Avatar asked Sep 21 '25 08:09

Hrvoje


1 Answers

You could use browser to make sure you are running in browser, then grab protocol from window.location.protocol.

<script context="module">
  import { browser } from "$app/env"
  if (browser) {
    console.log(window.location.protocol);
  }
</script>

From $app/env module section of sveltekit docs

like image 74
David Avatar answered Sep 23 '25 13:09

David