Skip to content

Commit

Permalink
feat(sandbox): add subdomain support
Browse files Browse the repository at this point in the history
Enables the sandbox feature to work when the node is hosted
on a subdomain.

Added to allow hosting on exiting domains.
  • Loading branch information
kay-is authored and djwhitt committed Sep 26, 2023
1 parent f5d6021 commit e71bda8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/middleware/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import { base32 } from 'rfc4648';

import { fromB64Url } from '../lib/encoding.js';

function getRequestSandbox(req: Request): string | undefined {
if (req.subdomains.length === 1) {
return req.subdomains[0];
function getRequestSandbox(req: Request, rootHost: string): string | undefined {
const rootHostSubdomainLength = rootHost.split('.').length - 2;
if (req.subdomains.length > rootHostSubdomainLength) {
return req.subdomains[req.subdomains.length - 1];
}
return undefined;
}
Expand Down Expand Up @@ -55,7 +56,7 @@ export function createSandboxMiddleware({
return;
}

const reqSandbox = getRequestSandbox(req);
const reqSandbox = getRequestSandbox(req, rootHost);
const idSandbox = sandboxFromId(id);
if (reqSandbox !== idSandbox) {
const queryString = url.parse(req.originalUrl).query ?? '';
Expand Down

0 comments on commit e71bda8

Please sign in to comment.