Skip to content

Instantly share code, notes, and snippets.

@alexindigo
Created January 8, 2015 20:03
Show Gist options
  • Save alexindigo/eaa9426f5e79a34b89a4 to your computer and use it in GitHub Desktop.
Save alexindigo/eaa9426f5e79a34b89a4 to your computer and use it in GitHub Desktop.
respond: function (req, res) {
if (!handle(req.url)) { return; }
var resource;
var parsedUrl = parseUrl(req.url);
var path = parsedUrl.pathname;
var mimeType = parsedUrl.params.rampMimeType;
var mounted = getMounted(path);
// if no mount explicitly specified
// scrap it from the cookie
// and check if resource exists
var contextPath = ((req.headers.cookie || '').match(/buster_contextPath=([^;]+)(;|$)/) || [])[1];
if (!mounted && contextPath) {
mounted = getMounted(contextPath);
// adjust path to check for the resource
if (mounted) {
parsedUrl = parseUrl(mounted.mountPoint + req.url);
path = parsedUrl.pathname;
mimeType = parsedUrl.params.rampMimeType;
}
// trying to get resource with new path
resource = getResource(mounted, resourcePath(mounted, path), mimeType);
// this is for real so adjust request
if (resource) {
req.url = mounted.mountPoint + req.url;
} else {
// didn't work out, put everything back
parsedUrl = parseUrl(req.url);
path = parsedUrl.pathname;
mimeType = parsedUrl.params.rampMimeType;
mounted = getMounted(path);
}
}
else
{
resource = getResource(mounted, resourcePath(mounted, path), mimeType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment