Skip to content

Commit

Permalink
fix: setup failed when secret is required
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Aug 27, 2023
1 parent 35a02e4 commit b660847
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/pages/Connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
import byteSize from 'byte-size'
import { isIPv6 } from 'is-ip'
import { For, createSignal } from 'solid-js'
import { wsEndpointURL } from '~/signals'
import { secret, wsEndpointURL } from '~/signals'
import type { Connection } from '../types'

export const Connections = () => {
const [search, setSearch] = createSignal('')

const ws = createReconnectingWS(`${wsEndpointURL()}/connections`)
const ws = createReconnectingWS(
`${wsEndpointURL()}/connections?token=${secret()}`,
)

const messageEvent = createEventSignal<{
message: WebSocketEventMap['message']
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Logs.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createEventSignal } from '@solid-primitives/event-listener'
import { createReconnectingWS } from '@solid-primitives/websocket'
import { For, createEffect, createSignal } from 'solid-js'
import { wsEndpointURL } from '~/signals'
import { secret, wsEndpointURL } from '~/signals'

export const Logs = () => {
const [search, setSearch] = createSignal('')
const [logs, setLogs] = createSignal<string[]>([])

const ws = createReconnectingWS(`${wsEndpointURL()}/logs`)
const ws = createReconnectingWS(`${wsEndpointURL()}/logs?token=${secret()}`)

const messageEvent = createEventSignal<{
message: WebSocketEventMap['message']
Expand Down
14 changes: 10 additions & 4 deletions src/pages/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApexOptions } from 'apexcharts'
import byteSize from 'byte-size'
import { SolidApexCharts } from 'solid-apexcharts'
import { createEffect, createMemo, createSignal } from 'solid-js'
import { wsEndpointURL } from '~/signals'
import { secret, wsEndpointURL } from '~/signals'
import type { Connection } from '~/types'

const defaultChartOptions: ApexOptions = {
Expand Down Expand Up @@ -40,7 +40,9 @@ export const Overview = () => {
)
const [memories, setMemories] = createSignal<number[]>([])

const trafficWS = createReconnectingWS(`${wsEndpointURL()}/traffic`)
const trafficWS = createReconnectingWS(
`${wsEndpointURL()}/traffic?token=${secret()}}`,
)

const trafficWSMessageEvent = createEventSignal<{
message: WebSocketEventMap['message']
Expand Down Expand Up @@ -76,7 +78,9 @@ export const Overview = () => {
},
])

const memoryWS = createReconnectingWS(`${wsEndpointURL()}/memory`)
const memoryWS = createReconnectingWS(
`${wsEndpointURL()}/memory?token=${secret()}`,
)

const memoryWSMessageEvent = createEventSignal<{
message: WebSocketEventMap['message']
Expand Down Expand Up @@ -108,7 +112,9 @@ export const Overview = () => {
},
])

const connectionsWS = createReconnectingWS(`${wsEndpointURL()}/connections`)
const connectionsWS = createReconnectingWS(
`${wsEndpointURL()}/connections?token=${secret()}}`,
)

const connectionsWSMessageEvent = createEventSignal<{
message: WebSocketEventMap['message']
Expand Down
10 changes: 9 additions & 1 deletion src/pages/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ export const Setup = () => {
const { form } = createForm<z.infer<typeof schema>>({
extend: validator({ schema }),
async onSubmit(values) {
const { hello } = await ky.get(values.url).json<{ hello: string }>()
const { hello } = await ky
.get(values.url, {
headers: values.secret
? {
Authorization: `Bearer ${values.secret}`,
}
: {},
})
.json<{ hello: string }>()

if (!hello) {
return
Expand Down
2 changes: 2 additions & 0 deletions src/signals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const [curTheme, setCurTheme] = makePersisted(
export const endpoint = () =>
endpointList().find(({ id }) => id === selectedEndpoint())

export const secret = () => endpoint()?.secret

export const wsEndpointURL = () => endpoint()?.url.replace('http', 'ws')

export const useRequest = () => {
Expand Down

0 comments on commit b660847

Please sign in to comment.