refactor(web): graphql url helper

This commit is contained in:
Zack Spear
2023-08-10 12:17:49 -07:00
parent 5aac3abbd3
commit 74b33d8473
3 changed files with 9 additions and 15 deletions

View File

@@ -3,7 +3,7 @@ import { storeToRefs } from 'pinia';
import { ArrowDownTrayIcon, ArrowTopRightOnSquareIcon } from '@heroicons/vue/24/solid';
import { useI18n } from 'vue-i18n';
import { DEV_GRAPH_URL, CONNECT_FORUMS, CONTACT, DISCORD } from '~/helpers/urls';
import { CONNECT_FORUMS, CONTACT, DISCORD, GRAPHQL } from '~/helpers/urls';
import { useServerStore } from '~/store/server';
import 'tailwindcss/tailwind.css';
import '~/assets/main.css';
@@ -12,7 +12,7 @@ const { t } = useI18n();
const { apiKey } = storeToRefs(useServerStore());
const downloadUrl = computed(() => new URL(`/graphql/api/logs?apiKey=${apiKey.value}`, DEV_GRAPH_URL.toString() || window.location.origin));
const downloadUrl = computed(() => new URL(`/graphql/api/logs?apiKey=${apiKey.value}`, GRAPHQL));
</script>
<template>

View File

@@ -9,8 +9,8 @@ const CONNECT_DOCS = new URL('https://docs.unraid.net/category/unraid-connect');
const CONNECT_DASHBOARD = new URL(import.meta.env.VITE_CONNECT ?? 'https://connect.myunraid.net');
const CONNECT_FORUMS = new URL('https://forums.unraid.net/forum/94-connect-plugin-support/');
const CONTACT = new URL('/contact', UNRAID_NET);
const DEV_GRAPH_URL = '';
const DISCORD = new URL('https://discord.gg/unraid');
const GRAPHQL = new URL('/graphql', import.meta.env.VITE_GRAPHQL ?? window.location.origin);
const PURCHASE_CALLBACK = new URL('/c', UNRAID_NET);
const SETTINGS_MANAGMENT_ACCESS = new URL('/Settings/ManagementAccess', window.location.origin);
@@ -23,8 +23,8 @@ export {
CONNECT_DOCS,
CONNECT_FORUMS,
CONTACT,
DEV_GRAPH_URL,
DISCORD,
GRAPHQL,
PURCHASE_CALLBACK,
PLUGIN_SETTINGS,
SETTINGS_MANAGMENT_ACCESS,

View File

@@ -11,6 +11,7 @@ import { defineStore, createPinia, setActivePinia } from 'pinia';
import { UserProfileLink } from 'types/userProfile';
import { WebguiUnraidApiCommand } from '~/composables/services/webgui';
import { GRAPHQL } from '~/helpers/urls';
import { useAccountStore } from '~/store/account';
// import { useErrorsStore } from '~/store/errors';
import { useServerStore } from '~/store/server';
@@ -24,18 +25,11 @@ setActivePinia(createPinia());
const ERROR_CORS_403 = 'The CORS policy for this site does not allow access from the specified Origin';
let prioritizeCorsError = false; // Ensures we don't overwrite this specific error message with a non-descriptive network error message
let baseUrl = window.location.origin;
/** @todo use ENV */
const localDevUrl = baseUrl.includes(':4321');
if (localDevUrl) {
/** @temp local dev mode */
baseUrl = baseUrl.replace(':4321', ':3001');
}
const httpEndpoint = new URL('/graphql', baseUrl);
const wsEndpoint = new URL('/graphql', baseUrl.replace('http', 'ws'));
const httpEndpoint = GRAPHQL;
const wsEndpoint = new URL(GRAPHQL.toString().replace('http', 'ws'));
console.debug('[useUnraidApiStore] httpEndpoint', httpEndpoint.toString());
console.debug('[useUnraidApiStore] wsEndpoint', wsEndpoint.toString());
console.debug('[unraidApi.ts] httpEndpoint', httpEndpoint);
console.debug('[unraidApi.ts] wsEndpoint', wsEndpoint);
export const useUnraidApiStore = defineStore('unraidApi', () => {
console.debug('[useUnraidApiStore]');