Static site hosting via tangled

Update

Changed files
+13 -16
src
+6 -7
src/server.js
··· 26 26 } 27 27 28 28 this.app.get("/{*any}", async (req, res) => { 29 + // Single site mode 30 + if (this.config.site) { 31 + return this.handleSiteRequest(req, res, this.config.site); 32 + } 33 + // Multi site mode 29 34 const subdomain = req.subdomains.at(-1); 30 - // Single site mode 31 35 if (!subdomain) { 32 - if (this.config.site) { 33 - return this.handleSiteRequest(req, res, this.config.site); 34 - } else { 35 - return res.status(200).send("Tangled pages is running!"); 36 - } 36 + return res.status(200).send("Tangled pages is running!"); 37 37 } 38 - // Multi site mode 39 38 const matchingSite = this.config.sites.find( 40 39 (site) => site.subdomain === subdomain 41 40 );
+7 -9
src/worker.js
··· 21 21 22 22 export default { 23 23 async fetch(request, env, ctx) { 24 + // Single site mode 25 + if (config.site) { 26 + return handleSiteRequest(request, config.site); 27 + } 28 + // Multi site mode 24 29 const url = new URL(request.url); 25 - const host = url.host; 26 30 const subdomainOffset = config.subdomainOffset ?? 2; 27 - const subdomain = host.split(".").at((subdomainOffset + 1) * -1); 28 - // Single site mode 31 + const subdomain = url.host.split(".").at((subdomainOffset + 1) * -1); 29 32 if (!subdomain) { 30 - if (config.site) { 31 - return handleSiteRequest(request, config.site); 32 - } else { 33 - return new Response("Tangled pages is running!", { status: 200 }); 34 - } 33 + return new Response("Tangled pages is running!", { status: 200 }); 35 34 } 36 - // Multi site mode 37 35 const matchingSite = config.sites?.find( 38 36 (site) => site.subdomain === subdomain 39 37 );