Created
January 8, 2015 20:03
-
-
Save alexindigo/eaa9426f5e79a34b89a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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