dynamic domain fetch in app
This commit is contained in:
parent
89953a70f3
commit
647649f9d9
Binary file not shown.
@ -1,28 +0,0 @@
|
||||
// (A) CREATE/INSTALL CACHE
|
||||
self.addEventListener("install", evt => {
|
||||
self.skipWaiting();
|
||||
evt.waitUntil(
|
||||
caches.open("Demo")
|
||||
.then(cache => cache.addAll([
|
||||
"index.html",
|
||||
"manifest.json"
|
||||
//"YOUR-STYLES.css",
|
||||
//"YOUR-SCRIPTS.js",
|
||||
//"YOUR-IMAGES.jpg"
|
||||
]))
|
||||
.catch(err => console.error(err))
|
||||
);
|
||||
});
|
||||
|
||||
// (B) CLAIM CONTROL INSTANTLY
|
||||
self.addEventListener("activate", evt => self.clients.claim());
|
||||
|
||||
// (C) LOAD FROM CACHE FIRST, FALLBACK TO NETWORK IF NOT FOUND
|
||||
self.addEventListener("fetch", evt => evt.respondWith(
|
||||
caches.match(evt.request).then(res => res || fetch(evt.request))
|
||||
));
|
||||
|
||||
/* (C) LOAD WITH NETWORK FIRST, FALLBACK TO CACHE IF OFFLINE
|
||||
self.addEventListener("fetch", evt => evt.respondWith(
|
||||
fetch(evt.request).catch(() => caches.match(evt.request))
|
||||
));*/
|
||||
@ -1,50 +1,91 @@
|
||||
<html><head> <meta charset="utf-8">
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no" name="viewport">
|
||||
|
||||
<!-- section:seometa -->
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:site_name" content="Discord">
|
||||
<meta property="og:title" content="Discord - A New Way to Chat with Friends & Communities">
|
||||
<meta property="og:description" content="Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities."><meta property="og:image" content="https://discord.com/assets/ee7c382d9257652a88c8f7b7f22a994d.png"> <meta name="twitter:card" content="summary_large_image">
|
||||
<meta property="og:title" content="Discord - A New Way to Chat with Friends & Communities">
|
||||
<meta property="og:description" content="Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.">
|
||||
<meta property="og:image" content="https://discord.com/assets/ee7c382d9257652a88c8f7b7f22a994d.png">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@discord">
|
||||
<meta name="twitter:creator" content="@discord">
|
||||
<!-- endsection -->
|
||||
<link rel="stylesheet" href="/assets/0.2b34836c33685cfed2cb.css" integrity="sha256-M5Vesh6YIz/Jhf7SDMllTJUN0sVnnsYMC1t5b0PgtrI= sha512-rMHRh3OkIAbI/gag1X+v6D4f9jbW1Qpx0Xl9f81B7KO+sXxoWdp53/IOfsfOCdYZDDhAuLZVq8+rbJln0x5ZMw=="><link rel="icon" href="/assets/07dca80a102d4149e9736d4b162cff6f.ico"> <!-- section:title -->
|
||||
<title>Discord</title>
|
||||
<!-- endsection -->
|
||||
<link rel="manifest" href="/assets/manifest.json">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app-mount"></div><script nonce="">window.__OVERLAY__ = /overlay/.test(location.pathname)</script><script nonce="">window.__BILLING_STANDALONE__ = /^\/billing/.test(location.pathname)</script><script nonce="">window.GLOBAL_ENV = {
|
||||
API_ENDPOINT: '//localhost:3001/api',
|
||||
WEBAPP_ENDPOINT: '//localhost:3001',
|
||||
CDN_HOST: 'localhost:3001',
|
||||
ASSET_ENDPOINT: 'http://localhost:3001',
|
||||
MEDIA_PROXY_ENDPOINT: 'http://localhost:3001',
|
||||
WIDGET_ENDPOINT: '//discord.com/widget',
|
||||
INVITE_HOST: 'discord.gg',
|
||||
GUILD_TEMPLATE_HOST: 'discord.new',
|
||||
GIFT_CODE_HOST: 'discord.gift',
|
||||
RELEASE_CHANNEL: 'stable',
|
||||
MARKETING_ENDPOINT: '//localhost:3001',
|
||||
BRAINTREE_KEY: 'production_5st77rrc_49pp2rp4phym7387',
|
||||
STRIPE_KEY: 'pk_live_CUQtlpQUF0vufWpnpUmQvcdi',
|
||||
NETWORKING_ENDPOINT: '//localhost:3001',
|
||||
RTC_LATENCY_ENDPOINT: '//localhost:3001',
|
||||
ACTIVITY_APPLICATION_HOST: 'localhost:3001',
|
||||
PROJECT_ENV: 'production',
|
||||
REMOTE_AUTH_ENDPOINT: '//remote-auth-gateway.discord.gg',
|
||||
SENTRY_TAGS: {"buildId":"9af39da","buildType":"normal"},
|
||||
MIGRATION_SOURCE_ORIGIN: 'http://localhost:3001',
|
||||
MIGRATION_DESTINATION_ORIGIN: 'http://localhost:3001',
|
||||
HTML_TIMESTAMP: Date.now(),
|
||||
ALGOLIA_KEY: 'aca0d7082e4e63af5ba5917d5e96bed0',
|
||||
};</script><script nonce="">!function(){if(null!=window.WebSocket){var n=function(n){try{var e=localStorage.getItem(n);return null==e?null:JSON.parse(e)}catch(n){return null}},e=n("token"),o=n("gatewayURL");if(e&&o&&!window.__OVERLAY__){var r=null!=window.DiscordNative||null!=window.require?"etf":"json",t=o+"/?encoding="+r+"&v=9&compress=zlib-stream";console.log("[FAST CONNECT] "+t+", encoding: "+r+", version: 9");var a=new WebSocket(t);a.binaryType="arraybuffer";var s=Date.now(),i={open:!1,gateway:t,messages:[]};a.onopen=function(){console.log("[FAST CONNECT] connected in "+(Date.now()-s)+"ms"),i.open=!0},a.onclose=a.onerror=function(){window._ws=null},a.onmessage=function(n){i.messages.push(n)},window._ws={ws:a,state:i}}}}();</script><script src="/assets/7bee670797b9a4c1e09e.js" integrity="sha256-R+g4DcQ56i9OB2SbBsSuHr/4jGHnajy0rWydMTqeDqg= sha512-g0U47mQ+/ULG8F6M3OC2B4ows6GWx/au7hwNQLBS+GSHOoxBBs43Phl2KUkAUgePNnBLnK3cx2+PwhUSsUw6Bw=="></script><script src="/assets/5ca4d4e888e24c4376b2.js" integrity="sha256-Fg+CWdC+LsYyaNS+ZzQIUX6aJ/txrGIQ0V5Z98veBmg= sha512-DL32yCQDhhq8oOHHlyIZZX6APXo4RZ2RoxIs4fn41o70RQyGQFHE4g/BwnObYFEWip2B3mHWqp+v1WdOFK9rQw=="></script><script src="/assets/70fef35cbb2412cacff1.js" integrity="sha256-7U4LjIJUe5h0HGIvMUEUGCeQtmzugNJyBAe1TdPq1go= sha512-TanKHdCiIsqnoq3DtURaab2MV6j2/3O5zMVhRWLzEvhu8sa2E70gRfcmjz4OfeHCLZPr+7Z+o2tRnyxpbIR2Ng=="></script><script src="/assets/d0ccd2ec4ae7fd5186b0.js"></script>
|
||||
<script>
|
||||
if ("serviceWorker" in navigator) { navigator.serviceWorker.register("/assets/test.js"); }
|
||||
</script>
|
||||
<style>
|
||||
<link rel="stylesheet" href="/assets/0.2b34836c33685cfed2cb.css">
|
||||
<link rel="icon" href="/assets/07dca80a102d4149e9736d4b162cff6f.ico">
|
||||
<link rel="manifest" href="/assets/manifest.json">
|
||||
<title>Discord</title>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
window.GLOBAL_ENV = {};
|
||||
window.__OVERLAY__ = /overlay/.test(location.pathname)
|
||||
window.__BILLING_STANDALONE__ = /^\/billing/.test(location.pathname)
|
||||
|
||||
function protocolRelative(url) {
|
||||
if (!url) return '';
|
||||
return '//' + url.replace(/^https?:\/\//, '').replace(/\/$/, '');
|
||||
}
|
||||
|
||||
async function loadGlobalEnv() {
|
||||
try {
|
||||
const res = await fetch("/api/v9/policies/instance/domains");
|
||||
const data = await res.json();
|
||||
|
||||
window.GLOBAL_ENV = {
|
||||
API_ENDPOINT: protocolRelative(data.apiEndpoint),
|
||||
WEBAPP_ENDPOINT: protocolRelative(data.apiEndpoint.replace(/\/api$/, '')),
|
||||
CDN_HOST: protocolRelative(data.cdn),
|
||||
ASSET_ENDPOINT: protocolRelative(data.cdn),
|
||||
MEDIA_PROXY_ENDPOINT: protocolRelative(data.cdn),
|
||||
WIDGET_ENDPOINT: '//discord.com/widget',
|
||||
INVITE_HOST: 'discord.gg',
|
||||
GUILD_TEMPLATE_HOST: 'discord.new',
|
||||
GIFT_CODE_HOST: 'discord.gift',
|
||||
RELEASE_CHANNEL: 'stable',
|
||||
MARKETING_ENDPOINT: protocolRelative(data.apiEndpoint.replace(/\/api$/, '')),
|
||||
BRAINTREE_KEY: 'production_5st77rrc_49pp2rp4phym7387',
|
||||
STRIPE_KEY: 'pk_live_CUQtlpQUF0vufWpnpUmQvcdi',
|
||||
NETWORKING_ENDPOINT: protocolRelative(data.apiEndpoint.replace(/\/api$/, '')),
|
||||
RTC_LATENCY_ENDPOINT: protocolRelative(data.apiEndpoint.replace(/\/api$/, '')),
|
||||
ACTIVITY_APPLICATION_HOST: protocolRelative(data.apiEndpoint.replace(/\/api$/, '')),
|
||||
PROJECT_ENV: 'production',
|
||||
REMOTE_AUTH_ENDPOINT: '//remote-auth-gateway.discord.gg',
|
||||
SENTRY_TAGS: { buildId: '9af39da', buildType: 'normal' },
|
||||
MIGRATION_SOURCE_ORIGIN: protocolRelative(data.apiEndpoint.replace(/\/api$/, '')),
|
||||
MIGRATION_DESTINATION_ORIGIN: protocolRelative(data.apiEndpoint.replace(/\/api$/, '')),
|
||||
HTML_TIMESTAMP: Date.now(),
|
||||
ALGOLIA_KEY: 'aca0d7082e4e63af5ba5917d5e96bed0',
|
||||
GATEWAY_URL: data.gateway
|
||||
};
|
||||
|
||||
const scripts = [
|
||||
'/assets/7bee670797b9a4c1e09e.js',
|
||||
'/assets/5ca4d4e888e24c4376b2.js',
|
||||
'/assets/70fef35cbb2412cacff1.js',
|
||||
'/assets/d0ccd2ec4ae7fd5186b0.js'
|
||||
];
|
||||
|
||||
scripts.forEach(src => {
|
||||
const s = document.createElement('script');
|
||||
s.src = src;
|
||||
s.defer = true;
|
||||
document.body.appendChild(s);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to load GLOBAL_ENV', e);
|
||||
}
|
||||
}
|
||||
|
||||
loadGlobalEnv();
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app-mount"></div>
|
||||
|
||||
<style>
|
||||
[class^="qrCodeOverlay"] {
|
||||
all: unset;
|
||||
background-image: url("/assets/pilkerton.png");
|
||||
@ -52,44 +93,13 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
[class*="qrCode-"][class*="spinner-"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
button[aria-label="Send a gift"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
a[href="/store"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.platform-win .notice-3bPHh- {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div[aria-controls="Discord Nitro-tab"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div[aria-controls="Nitro Server Boost-tab"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div[aria-controls="Nitro Server Boost-tab"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div[aria-controls="Library Inventory-tab"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div[aria-controls="Billing-tab"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
</body></html>
|
||||
[class*="qrCode-"][class*="spinner-"] { display: none; }
|
||||
button[aria-label="Send a gift"], a[href="/store"] { display: none; }
|
||||
.platform-win .notice-3bPHh- { display: none; }
|
||||
div[aria-controls="Discord Nitro-tab"],
|
||||
div[aria-controls="Nitro Server Boost-tab"],
|
||||
div[aria-controls="Library Inventory-tab"],
|
||||
div[aria-controls="Billing-tab"] { display: none; }
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -91,7 +91,7 @@ export class SpacebarServer extends Server {
|
||||
await initTranslation(api);
|
||||
|
||||
this.routes = await registerRoutes(this, path.join(__dirname, "routes", "/"));
|
||||
|
||||
|
||||
this.app = app;
|
||||
|
||||
//app.use("/__development", )
|
||||
@ -103,7 +103,8 @@ export class SpacebarServer extends Server {
|
||||
app.use("/api", api); // allow unversioned requests
|
||||
|
||||
app.use("/imageproxy/:hash/:size/:url", ImageProxy);
|
||||
// for the 2021 discord frontend, can be replaced with anything else, just respect the way this file is structured
|
||||
|
||||
// for the discord frontend, can be replaced with anything else, just respect the way this file is structured
|
||||
app.use("/assets", express.static(path.join(PUBLIC_ASSETS_FOLDER, "client")));
|
||||
|
||||
app.get("/verify-email", (req, res) => res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "verify.html")));
|
||||
@ -115,18 +116,18 @@ export class SpacebarServer extends Server {
|
||||
app.get("/_spacebar/api/openapi.json", (req, res) => {
|
||||
res.sendFile(path.join(ASSETS_FOLDER, "openapi.json"));
|
||||
});
|
||||
|
||||
|
||||
app.use("*_", (req, res) => res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "index.html")));
|
||||
|
||||
// current well-known location (new commit 22 nov 2025 from spacebar)
|
||||
app.get("/.well-known/spacebar", (req,res)=>{
|
||||
|
||||
// current well-known location (new commit 22 nov 2025 from spacebar)
|
||||
app.get("/.well-known/spacebar", (req, res) => {
|
||||
res.json({
|
||||
api: Config.get().api.endpointPublic
|
||||
api: Config.get().api.endpointPublic,
|
||||
});
|
||||
});
|
||||
|
||||
// new well-known location
|
||||
app.get("/.well-known/spacebar/client", (req,res)=>{
|
||||
app.get("/.well-known/spacebar/client", (req, res) => {
|
||||
let erlpackSupported = false;
|
||||
try {
|
||||
require("@yukikaze-bot/erlpack");
|
||||
@ -140,20 +141,20 @@ export class SpacebarServer extends Server {
|
||||
baseUrl: Config.get().api.endpointPublic?.split("/api")[0] || "", // TODO: migrate database values to not include /api/v9
|
||||
apiVersions: {
|
||||
default: Config.get().api.defaultVersion,
|
||||
active: Config.get().api.activeVersions
|
||||
}
|
||||
active: Config.get().api.activeVersions,
|
||||
},
|
||||
},
|
||||
cdn: {
|
||||
baseUrl: Config.get().cdn.endpointPublic
|
||||
baseUrl: Config.get().cdn.endpointPublic,
|
||||
},
|
||||
gateway: {
|
||||
baseUrl: Config.get().gateway.endpointPublic,
|
||||
encoding: [...(erlpackSupported ? ["etf"] : []), "json"],
|
||||
compression: ["zstd-stream", "zlib-stream", null],
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
this.app.use(ErrorHandler);
|
||||
|
||||
ConnectionLoader.loadConnections();
|
||||
|
||||
Reference in New Issue
Block a user