@compas/stdlib
Advanced tools
Comparing version 0.0.127 to 0.0.128
@@ -10,2 +10,4 @@ export { uuid } from "./src/datatypes.js"; | ||
refreshEnvironmentCache, | ||
calculateCorsUrlFromAppUrl, | ||
calculateCookieUrlFromAppUrl, | ||
} from "./src/env.js"; | ||
@@ -12,0 +14,0 @@ |
{ | ||
"name": "@compas/stdlib", | ||
"version": "0.0.127", | ||
"version": "0.0.128", | ||
"description": "All kinds of utility functions", | ||
@@ -16,3 +16,3 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@compas/insight": "0.0.127", | ||
"@compas/insight": "0.0.128", | ||
"@types/node": "14.14.37", | ||
@@ -43,3 +43,3 @@ "dotenv": "8.2.0", | ||
}, | ||
"gitHead": "5bc1438cddeb96b50f0395f7de18ba5c1c5b8c91" | ||
"gitHead": "0ca512dd447ebebc6c6793e2728cfb4c172b0181" | ||
} |
@@ -59,1 +59,56 @@ /** | ||
} | ||
/** | ||
* Try to calculate the CORS_URL environment variable from the APP_URL environment | ||
* variable. Assumes the APP_URL is in the following format: http(s)://api.xxx.xx.com and | ||
* generates the following CORS_URL value: http(s)://xxx.xx.com. | ||
* If the APP_URL host only contains xxx.com the CORS_URL value will be equivalent. | ||
* | ||
* Refreshing the environment cache via `refreshEnvironmentCache` is not necessary. | ||
* | ||
* @since 0.1.0 | ||
* | ||
* @returns {void} | ||
*/ | ||
export function calculateCorsUrlFromAppUrl() { | ||
const appUrl = new URL(environment.APP_URL); | ||
const hostParts = appUrl.host.split("."); | ||
const protocol = appUrl.protocol; | ||
let corsUrl = ""; | ||
if (hostParts.length === 2) { | ||
corsUrl = `${protocol}//${appUrl.host}`; | ||
} else { | ||
corsUrl = `${protocol}//${hostParts.slice(1).join(".")}`; | ||
} | ||
environment.CORS_URL = corsUrl; | ||
process.env.CORS_URL = corsUrl; | ||
} | ||
/** | ||
* Try to calculate the COOKIE_URL environment variable from the APP_URL environment | ||
* variable. Assumes the APP_URL is in the following format: http(s)://api.xxx.xx.com and | ||
* generates the following COOKIE_URL value: xxx.xx.com. | ||
* If the APP_URL host only contains xxx.com the CORS_URL value will be equivalent. | ||
* | ||
* Refreshing the environment cache via `refreshEnvironmentCache` is not necessary. | ||
* | ||
* @since 0.1.0 | ||
* | ||
* @returns {void} | ||
*/ | ||
export function calculateCookieUrlFromAppUrl() { | ||
const appUrl = new URL(environment.APP_URL); | ||
const hostParts = appUrl.host.split("."); | ||
let cookieUrl = appUrl.host; | ||
if (hostParts.length !== 2) { | ||
cookieUrl = hostParts.slice(1).join("."); | ||
} | ||
environment.COOKIE_URL = cookieUrl; | ||
process.env.COOKIE_URL = cookieUrl; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33468
1077
+ Added@compas/insight@0.0.128(transitive)
- Removed@compas/insight@0.0.127(transitive)
Updated@compas/insight@0.0.128