Archived
1
0

Improve routing

This commit is contained in:
Asher
2020-02-04 18:16:45 -06:00
parent dbc5c065f8
commit 8cc11d1688
26 changed files with 289 additions and 267 deletions

View File

@ -1,6 +1,7 @@
export interface Application {
readonly comment?: string
readonly directory?: string
readonly embedPath?: string
readonly exec?: string
readonly icon?: string
readonly loaded?: boolean

View File

@ -1,6 +1,9 @@
import { logger } from "@coder/logger"
import { Application } from "../common/api"
export interface Options {
app?: Application
authed?: boolean
logLevel?: number
}
@ -27,6 +30,9 @@ export const generateUuid = (length = 24): string => {
* Get options embedded in the HTML from the server.
*/
export const getOptions = <T extends Options>(): T => {
if (typeof document === "undefined") {
return {} as T
}
const el = document.getElementById("coder-options")
try {
if (!el) {
@ -46,3 +52,10 @@ export const getOptions = <T extends Options>(): T => {
return {} as T
}
}
/**
* Remove extra slashes in a URL.
*/
export const normalize = (url: string, keepTrailing = false): string => {
return url.replace(/\/\/+/g, "/").replace(/\/+$/, keepTrailing ? "/" : "")
}