Skip to content

Commit

Permalink
Default to the same host when determing WebSocket URL
Browse files Browse the repository at this point in the history
We still need to be able to override it in order to use the Sveltekit dev server
  • Loading branch information
Jalle19 committed Oct 15, 2023
1 parent 401e5e6 commit acc214a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 0 additions & 1 deletion webif/src/lib/index.ts

This file was deleted.

9 changes: 9 additions & 0 deletions webif/src/lib/websocket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const determineWebSocketUrl = () => {
const urlParams = new URLSearchParams(window.location.search)

// Use whatever is specified by the "ws" query parameter, default
// to the current host of nothing is specified. This allows us to
// manually define the WebSocket host when running the Svelte
// development server.
return urlParams.get('ws') || `ws://${window.location.host}`
}
8 changes: 2 additions & 6 deletions webif/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script>
import { onMount } from 'svelte'
import { determineWebSocketUrl } from '$lib/websocket'
import Logo from './Logo.svelte'
import Configuration from './Configuration.svelte'
import LastUpdate from './LastUpdate.svelte'
Expand All @@ -14,12 +16,6 @@
let mainsSensorData
let circuitSensorData
const determineWebSocketUrl = () => {
const urlParams = new URLSearchParams(window.location.search)
return urlParams.get('ws') || undefined
}
const parseTimestamp = (sensorData) => {
return new Date(sensorData[0].timestamp)
}
Expand Down

0 comments on commit acc214a

Please sign in to comment.