Browse Source

fix(gui-v2): baseURL

pull/3273/head
Wing-Kam Wong 2 years ago
parent
commit
8c5780cf3e
  1. 6
      packages/nc-gui-v2/components/dlg/AirtableImport.vue
  2. 6
      packages/nc-gui-v2/composables/useApi/index.ts
  3. 2
      packages/nc-gui-v2/composables/useGlobal/state.ts
  4. 7
      packages/nc-gui-v2/plugins/tele.ts

6
packages/nc-gui-v2/components/dlg/AirtableImport.vue

@ -11,6 +11,7 @@ import {
onBeforeUnmount, onBeforeUnmount,
onMounted, onMounted,
ref, ref,
useGlobal,
useNuxtApp, useNuxtApp,
useProject, useProject,
watch, watch,
@ -24,8 +25,9 @@ const { modelValue } = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
// TODO: handle baseURL const { appInfo } = $(useGlobal())
const baseURL = 'http://localhost:8080' // this.$axios.defaults.baseURL
const baseURL = appInfo.ncSiteUrl
const { $state } = useNuxtApp() const { $state } = useNuxtApp()

6
packages/nc-gui-v2/composables/useApi/index.ts

@ -3,12 +3,14 @@ import { Api } from 'nocodb-sdk'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import type { CreateApiOptions, UseApiProps, UseApiReturn } from './types' import type { CreateApiOptions, UseApiProps, UseApiReturn } from './types'
import { addAxiosInterceptors } from './interceptors' import { addAxiosInterceptors } from './interceptors'
import { createEventHook, ref, unref, useCounter, useNuxtApp } from '#imports' import { createEventHook, ref, unref, useCounter, useGlobal, useNuxtApp } from '#imports'
export function createApiInstance<SecurityDataType = any>(options: CreateApiOptions = {}): Api<SecurityDataType> { export function createApiInstance<SecurityDataType = any>(options: CreateApiOptions = {}): Api<SecurityDataType> {
const { appInfo } = $(useGlobal())
return addAxiosInterceptors( return addAxiosInterceptors(
new Api<SecurityDataType>({ new Api<SecurityDataType>({
baseURL: options.baseURL ?? 'http://localhost:8080', baseURL: options.baseURL ?? appInfo.ncSiteUrl,
}), }),
) )
} }

2
packages/nc-gui-v2/composables/useGlobal/state.ts

@ -77,7 +77,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
}) })
const appInfo = ref<AppInfo>({ const appInfo = ref<AppInfo>({
ncSiteUrl: 'localhost:8080', ncSiteUrl: 'http://localhost:8080',
authType: 'jwt', authType: 'jwt',
connectToExternalDB: false, connectToExternalDB: false,
defaultLimit: 0, defaultLimit: 0,

7
packages/nc-gui-v2/plugins/tele.ts

@ -6,16 +6,19 @@ import type { UseGlobalReturn } from '~/composables/useGlobal/types'
// todo: ignore init if tele disabled // todo: ignore init if tele disabled
export default defineNuxtPlugin(async (nuxtApp) => { export default defineNuxtPlugin(async (nuxtApp) => {
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
const { appInfo } = $(useGlobal())
let socket: Socket let socket: Socket
const init = async (token: string) => { const init = async (token: string) => {
try { try {
if (socket) socket.disconnect() if (socket) socket.disconnect()
// todo: extract base url const url = new URL(appInfo.ncSiteUrl, window.location.href.split(/[?#]/)[0]).href
const url = 'http://localhost:8080' // new URL($axios.defaults.baseURL, window.location.href.split(/[?#]/)[0]).href
socket = io(url, { socket = io(url, {
extraHeaders: { 'xc-auth': token }, extraHeaders: { 'xc-auth': token },
}) })

Loading…
Cancel
Save