Add basic web app and API integration
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const API_BASE = "http://127.0.0.1:8080";
|
||||
|
||||
function getApiBase() {
|
||||
return API_BASE;
|
||||
}
|
||||
|
||||
function apiURL(path) {
|
||||
const base = getApiBase();
|
||||
if (!base) return path;
|
||||
return base + path;
|
||||
}
|
||||
|
||||
function wsURL(path) {
|
||||
const base = getApiBase();
|
||||
if (base) {
|
||||
let u;
|
||||
try { u = new URL(base); } catch (e) { return null; }
|
||||
u.protocol = u.protocol === "https:" ? "wss:" : "ws:";
|
||||
u.pathname = u.pathname.replace(/\/+$/, "") + path;
|
||||
return u.toString();
|
||||
}
|
||||
const proto = location.protocol === "https:" ? "wss:" : "ws:";
|
||||
return `${proto}//${location.host}${path}`;
|
||||
}
|
||||
Reference in New Issue
Block a user