From 7494a12f8b64d6492ebb3c29a5ab734b1db4773e Mon Sep 17 00:00:00 2001 From: Ade Novid Date: Fri, 16 Feb 2024 09:46:46 +0700 Subject: [PATCH] fix: env undefined in client side --- src/runtime/nuapi.ts | 32 ++++++++++++++++---------------- types/env.d.ts | 6 ++++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/runtime/nuapi.ts b/src/runtime/nuapi.ts index ca11127..79f7659 100644 --- a/src/runtime/nuapi.ts +++ b/src/runtime/nuapi.ts @@ -31,25 +31,13 @@ export default defineNuxtPlugin(() => { const browserId = ref() const route = useRoute() - const appName = useState(() => env.APP_NAME) - const appVersion = useState(() => env.APP_VERSION || env.BUILD_VERSION) - const platformName = useState(() => env.APP_PLATFORM_NAME || env.PLATFORM_NAME) - const platformType = useState(() => env.APP_PLATFORM_TYPE || env.PLATFORM_TYPE) + const appName = useState('appName', () => env.APP_NAME) + const appVersion = useState('appVersion', () => env.APP_VERSION || env.BUILD_VERSION) + const platformName = useState('platformName', () => env.APP_PLATFORM_NAME || env.PLATFORM_NAME) + const platformType = useState('platformType', () => env.APP_PLATFORM_TYPE || env.PLATFORM_TYPE) onRequest(async (config) => { if (config.headers) { - /** - * Add Request ID - */ - if (!config.headers['X-Request-Id']) - config.headers['X-Request-Id'] = uuidv4() - - /** - * Add Request timestamp - */ - if (!config.headers['X-Request-Timestamp']) - config.headers['X-Request-Timestamp'] = Date.now().toString() - /** * Add Browser's fingerprint */ @@ -105,6 +93,18 @@ export default defineNuxtPlugin(() => { */ if (route.query.testing === 'true') config.headers['X-Testing-Mode'] = true + + /** + * Add Request ID + */ + if (!config.headers['X-Request-Id']) + config.headers['X-Request-Id'] = uuidv4() + + /** + * Add Request timestamp + */ + if (!config.headers['X-Request-Timestamp']) + config.headers['X-Request-Timestamp'] = Date.now().toString() } return config diff --git a/types/env.d.ts b/types/env.d.ts index 7f0dc08..51e05bc 100644 --- a/types/env.d.ts +++ b/types/env.d.ts @@ -4,7 +4,8 @@ interface ImportMetaEnv { readonly APP_NAME: string, readonly APP_VERSION: string, - readonly APP_PLATFORM: string, + readonly APP_PLATFORM_NAME: string, + readonly APP_PLATFORM_TYPE: string, readonly BUILD_VERSION: string, readonly BUILD_DATE: string, @@ -20,7 +21,8 @@ declare global { interface ProcessEnv { readonly APP_NAME: string, readonly APP_VERSION: string, - readonly APP_PLATFORM: string, + readonly APP_PLATFORM_NAME: string, + readonly APP_PLATFORM_TYPE: string, readonly BUILD_VERSION: string, readonly BUILD_DATE: string,