Skip to content

Commit

Permalink
add typing for import.meta.env
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Jan 26, 2023
1 parent 5dde591 commit cb568ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions packages/editor-ui/src/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ declare module 'markdown-it-emoji';
declare module 'markdown-it-task-lists';

declare global {
interface ImportMeta {
env: {
DEV: boolean;
PROD: boolean;
NODE_ENV: 'development' | 'production';
VUE_APP_URL_BASE_API: string;
VUE_APP_ENDPOINT_REST?: string;
};
}

interface Window {
BASE_PATH: string;
}
Expand Down
18 changes: 8 additions & 10 deletions packages/editor-ui/src/stores/n8nRootStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { defineStore } from 'pinia';
import Vue from 'vue';
import { useNodeTypesStore } from './nodeTypes';

const { VUE_APP_URL_BASE_API, VUE_APP_ENDPOINT_REST } = import.meta.env;

export const useRootStore = defineStore(STORES.ROOT, {
state: (): RootState => ({
// @ts-ignore
baseUrl: import.meta.env.VUE_APP_URL_BASE_API
? import.meta.env.VUE_APP_URL_BASE_API
: window.BASE_PATH === '/{{BASE_PATH}}/'
? '/'
: window.BASE_PATH,
baseUrl:
VUE_APP_URL_BASE_API ?? window.BASE_PATH === '/{{BASE_PATH}}/' ? '/' : window.BASE_PATH,
defaultLocale: 'en',
endpointWebhook: 'webhook',
endpointWebhookTest: 'webhook-test',
Expand Down Expand Up @@ -44,16 +42,16 @@ export const useRootStore = defineStore(STORES.ROOT, {

getRestUrl(): string {
let endpoint = 'rest';
if (import.meta.env.VUE_APP_ENDPOINT_REST) {
endpoint = import.meta.env.VUE_APP_ENDPOINT_REST;
if (VUE_APP_ENDPOINT_REST) {
endpoint = VUE_APP_ENDPOINT_REST;
}
return `${this.baseUrl}${endpoint}`;
},

getRestApiContext(): IRestApiContext {
let endpoint = 'rest';
if (import.meta.env.VUE_APP_ENDPOINT_REST) {
endpoint = import.meta.env.VUE_APP_ENDPOINT_REST;
if (VUE_APP_ENDPOINT_REST) {
endpoint = VUE_APP_ENDPOINT_REST;
}
return {
baseUrl: `${this.baseUrl}${endpoint}`,
Expand Down

0 comments on commit cb568ad

Please sign in to comment.