Gateway: fallback routes per host, for the laptop's VPN address
This commit is contained in:
1 parent
f46c803ad4
commit
42b6a4920c
8 files changed
+151
-20
No files matched your search
+8
-4
@@ -8,6 +8,8 @@ export interface HostRow {
|
||||
id: string;
|
||||
label: string;
|
||||
url: string;
|
||||
/** Fallback routes to the same server, as a JSON array, tried in order after `url`. */
|
||||
alt_urls: string | null;
|
||||
environment_id: string;
|
||||
token: string;
|
||||
token_expires_at: string | null;
|
||||
@@ -61,17 +63,19 @@ export function openDb(path: string) {
|
||||
db.run("pragma journal_mode = wal");
|
||||
db.run("pragma busy_timeout = 5000");
|
||||
db.run(SCHEMA);
|
||||
const hostColumns = db.query<{ name: string }, []>("pragma table_info(hosts)").all().map((column) => column.name);
|
||||
if (!hostColumns.includes("alt_urls")) db.run("alter table hosts add column alt_urls text");
|
||||
|
||||
return {
|
||||
hosts: {
|
||||
list: () => db.query<HostRow, []>("select * from hosts order by created_at").all(),
|
||||
upsert(host: Omit<HostRow, "created_at">) {
|
||||
db.query(
|
||||
`insert into hosts (id, label, url, environment_id, token, token_expires_at, created_at)
|
||||
values ($id, $label, $url, $environment_id, $token, $token_expires_at, $created_at)
|
||||
`insert into hosts (id, label, url, alt_urls, environment_id, token, token_expires_at, created_at)
|
||||
values ($id, $label, $url, $alt_urls, $environment_id, $token, $token_expires_at, $created_at)
|
||||
on conflict(environment_id) do update set
|
||||
label = excluded.label, url = excluded.url, token = excluded.token,
|
||||
token_expires_at = excluded.token_expires_at`,
|
||||
label = excluded.label, url = excluded.url, alt_urls = excluded.alt_urls,
|
||||
token = excluded.token, token_expires_at = excluded.token_expires_at`,
|
||||
).run({ ...host, created_at: now() });
|
||||
},
|
||||
remove: (idOrLabel: string) =>
|
||||
|
||||
Reference in new issue
Block a user