-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh: get rid of computed property and introduce a new `resolveApiUrlP…
…ath` helper
- Loading branch information
1 parent
d3e8050
commit 013fcc2
Showing
11 changed files
with
363 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,8 @@ | |
"dev:prepare": "nuxt-module-build build --stub", | ||
"docs:dev": "vitepress dev docs", | ||
"docs:build": "vitepress build docs", | ||
"docs:preview": "vitepress preview docs" | ||
"docs:preview": "vitepress preview docs", | ||
"test:unit": "vitest" | ||
}, | ||
"dependencies": { | ||
"@nuxt/kit": "^3.12.4", | ||
|
@@ -61,6 +62,7 @@ | |
"ts-essentials": "^9.4.2", | ||
"typescript": "^5.5.4", | ||
"vitepress": "^1.3.1", | ||
"vitest": "^1.6.0", | ||
"vue-tsc": "^2.0.29" | ||
}, | ||
"packageManager": "[email protected]+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/runtime/utils/local.ts → src/runtime/composables/local/utils/token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { joinURL } from 'ufo' | ||
|
||
// Slimmed down type to allow easy unit testing | ||
interface RuntimeConfig { | ||
public: { | ||
auth: { | ||
baseURL: string | ||
originEnvKey: string | ||
} | ||
} | ||
} | ||
|
||
// TODO Comment below: remove/rewrite/add to docs | ||
// Prios in runtime (baseURL): | ||
// - env variable (using `originEnvKey`); | ||
// - static runtime config (`baseURL` captured during build); | ||
// - defaults; | ||
export function resolveApiUrlPath( | ||
endpointPath: string, | ||
runtimeConfig: RuntimeConfig | ||
): string { | ||
// Fully-specified endpoint path - do not join with `baseURL` | ||
if (endpointPath.startsWith('http://') || endpointPath.startsWith('https://')) { | ||
return endpointPath | ||
} | ||
|
||
const authRuntimeConfig = runtimeConfig.public.auth | ||
|
||
// Default to static runtime config (still overridable using `NUXT_PUBLIC_AUTH_BASE_URL`) | ||
let baseURL = authRuntimeConfig.baseURL | ||
|
||
// Override base URL using environment variable specified in `originEnvKey` if any | ||
if (authRuntimeConfig.originEnvKey) { | ||
const envBaseURL = process.env[authRuntimeConfig.originEnvKey] | ||
if (envBaseURL) { | ||
baseURL = envBaseURL | ||
} | ||
} | ||
|
||
return joinURL(baseURL, endpointPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.