feat: add link creation and lookup
finally has the bare minimum functionality to say that it works!
This commit is contained in:
@@ -35,3 +35,53 @@ export function getString(
|
||||
return process.env[keyName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the environmental boolean from .env.
|
||||
* Supports rewriting names to UPPER_SNAKE_CASE if isGlobal is set.
|
||||
*
|
||||
* @param {string} key The key
|
||||
* @param {boolean} [isGlobal=true] Indicates if global
|
||||
* @return {(boolean|undefined)} The environment boolean.
|
||||
*/
|
||||
export function getBool(
|
||||
key: string,
|
||||
isGlobal: boolean = true
|
||||
): boolean | undefined {
|
||||
|
||||
const valueRead: string | undefined = getString(key, isGlobal);
|
||||
if (valueRead === undefined) return undefined;
|
||||
if (valueRead.toLowerCase() === 'true')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes public url, returning protocol, fqdn and path.
|
||||
* proto://fqdn/path/ = fullPublicUrl
|
||||
* @return {RewriteStrings} The rewrite strings.
|
||||
*/
|
||||
export function getRewriteStrings(): RewriteStrings {
|
||||
const fullPublicUrl: string = getString('publicUrl', true)!;
|
||||
|
||||
const url = new URL(fullPublicUrl);
|
||||
const proto = url.protocol.slice(0, -1); // https: -> https
|
||||
const fqdn = url.host;
|
||||
const path = url.pathname.replace(/\/+$/, '') + '/'; // /abc -> /abc/
|
||||
|
||||
const result: RewriteStrings = {
|
||||
fullPublicUrl,
|
||||
proto,
|
||||
fqdn,
|
||||
path
|
||||
};
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export type RewriteStrings = {
|
||||
fullPublicUrl: string;
|
||||
proto: string;
|
||||
fqdn: string;
|
||||
path: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user