Use proper urls

This commit is contained in:
dragongoose 2023-04-08 20:04:28 -04:00
parent 4e6bde767d
commit 8ecb77e430
No known key found for this signature in database
GPG Key ID: 50DB99B921579009
7 changed files with 30 additions and 20 deletions

5
.env
View File

@ -1,2 +1,3 @@
VITE_BACKEND_URL=http://localhost:7000 VITE_BACKEND_DOMAIN=localhost:7000
VITE_INSTANCE_URL=http://localhost:5173 VITE_INSTANCE_DOMAIN=localhost:5173
VITE_HTTPS=false

5
env.d.ts vendored
View File

@ -1,8 +1,9 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VITE_BACKEND_URL: string readonly VITE_BACKEND_DOMAIN: string
readonly VITE_INSTANCE_URL: string readonly VITE_INSTANCE_DOMAIN: string
readonly VITE_HTTPS: string
// more env variables... // more env variables...
} }

View File

@ -20,11 +20,12 @@ export default {
} }
}, },
async setup(props) { async setup(props) {
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
let streamData: Stream | null = null let streamData: Stream | null = null
if (!props.stream && props.name) { if (!props.stream && props.name) {
const streamDataFetch = await fetch( const streamDataFetch = await fetch(
`${import.meta.env.VITE_BACKEND_URL}/api/users/${props.name}` `${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/users/${props.name}`
) )
const data = await streamDataFetch.json() const data = await streamDataFetch.json()
@ -36,11 +37,12 @@ export default {
streamData = props.stream as Stream streamData = props.stream as Stream
} }
const frontend_url = import.meta.env.VITE_INSTANCE_URL const frontend_url = protocol + import.meta.env.VITE_INSTANCE_DOMAIN
return { return {
frontend_url, frontend_url,
streamData streamData,
protocol
} }
}, },
methods: { methods: {
@ -58,10 +60,9 @@ export default {
<template> <template>
<div v-if="streamData"> <div v-if="streamData">
<div class="bg-ctp-crust rounded-lg w-[27rem]"> <div class="bg-ctp-crust rounded-lg w-[27rem]">
<a :href="`${frontend_url}/${streamData.streamer.name}`"> <RouterLink :to="'/' + streamData.streamer.name">
<img :src="streamData.preview" class="rounded-lg rounded-b-none" /> <img :src="streamData.preview" class="rounded-lg rounded-b-none" />
</a> </RouterLink>
<div class="text-white p-2 inline-flex space-x-2 w-full h-16"> <div class="text-white p-2 inline-flex space-x-2 w-full h-16">
<div class="inline-flex"> <div class="inline-flex">
<div class="inline-flex"> <div class="inline-flex">

View File

@ -19,12 +19,13 @@ export default {
}, },
async setup(props) { async setup(props) {
let messages: Ref<ParsedMessage[]> = ref([]) let messages: Ref<ParsedMessage[]> = ref([])
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
const badgesFetch = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/badges?channelName=${props.channelName}`) const badgesFetch = await fetch(`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/badges?channelName=${props.channelName}`)
let badges: Badge[] = await badgesFetch.json() let badges: Badge[] = await badgesFetch.json()
return { return {
ws: new WebSocket(`ws://localhost:7001`), ws: new WebSocket(`ws://${import.meta.env.VITE_BACKEND_DOMAIN}`),
messages, messages,
badges, badges,
props, props,
@ -57,7 +58,7 @@ export default {
}, },
clearMessages() { clearMessages() {
if (this.messages.length > 50) { if (this.messages.length > 50) {
this.messages.shift this.messages.shift()
} }
}, },
getBadges(message: ParsedMessage) { getBadges(message: ParsedMessage) {

View File

@ -4,11 +4,13 @@ import StreamPreviewVue from '@/components/StreamPreview.vue'
export default { export default {
async setup() { async setup() {
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
const route = useRoute() const route = useRoute()
const game = route.params.game const game = route.params.game
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover/${game}`) const res = await fetch(`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/${game}`)
const data = await res.json() const data = await res.json()
let frontend_url = import.meta.env.VITE_INSTANCE_URL let frontend_url = protocol + import.meta.env.VITE_INSTANCE_DOMAIN
return { return {
data, data,
frontend_url frontend_url

View File

@ -4,13 +4,16 @@ import StreamPreviewVue from '@/components/StreamPreview.vue'
export default { export default {
async setup() { async setup() {
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover`) const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
const res = await fetch(`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover`)
let data: Ref<any[] | undefined> = ref() let data: Ref<any[] | undefined> = ref()
let frontend_url = import.meta.env.VITE_INSTANCE_URL let frontend_url = protocol + import.meta.env.VITE_INSTANCE_DOMAIN
data.value = await res.json() data.value = await res.json()
return { return {
data, data,
protocol,
frontend_url, frontend_url,
filterTags: '', filterTags: '',
following: ref([]) following: ref([])
@ -62,7 +65,7 @@ export default {
const cursor = this.data[this.data.length - 1].cursor const cursor = this.data[this.data.length - 1].cursor
if (!cursor) return if (!cursor) return
const res = await fetch( const res = await fetch(
`${import.meta.env.VITE_BACKEND_URL}/api/discover/?cursor=${cursor}` `${this.protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/?cursor=${cursor}`
) )
const data = await res.json() const data = await res.json()

View File

@ -10,9 +10,10 @@ export default {
async setup() { async setup() {
const route = useRoute() const route = useRoute()
const username = route.params.username const username = route.params.username
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
const getUser = async () => { const getUser = async () => {
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/users/${username}`) const res = await fetch(`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/users/${username}`)
if (res.status !== 200) { if (res.status !== 200) {
const data = await res.json() const data = await res.json()
@ -46,7 +47,7 @@ export default {
controls: true, controls: true,
sources: [ sources: [
{ {
src: `${import.meta.env.VITE_BACKEND_URL}/proxy/stream/${username}/hls.m3u8`, src: `${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/proxy/stream/${username}/hls.m3u8`,
type: 'application/vnd.apple.mpegurl' type: 'application/vnd.apple.mpegurl'
} }
], ],