Discard protocol, host, and port of URLs in bundle options

Summary:
HTTP request URLs don’t include protocol, host and port. Stack frames URLs, on the other hand, contain full URLs. These full URLs are used to get the correct bundle to build the source map from.

The method that creates option objects from URLs therefore now discards leading protocol, host and port to ensure that cached bundles can be reused for symbolication rather than triggering rebuilds.

Reviewed By: jeanlauliac, cpojer

Differential Revision: D4598077

fbshipit-source-id: 262df187bcdf7099011371e8b55ae692c6e1a942
This commit is contained in:
David Aurelio 2017-02-23 02:32:08 -08:00 committed by Facebook Github Bot
parent 7e8ab0d237
commit 6fa8dedfb5
2 changed files with 19 additions and 4 deletions

View File

@ -540,6 +540,15 @@ describe('processRequest', () => {
});
});
describe('_getOptionsFromUrl', () => {
it('ignores protocol, host and port of the passed in URL', () => {
const short = '/path/to/entry-file.js??platform=ios&dev=true&minify=false';
const long = `http://localhost:8081${short}`;
expect(server._getOptionsFromUrl(long))
.toEqual(server._getOptionsFromUrl(short));
});
});
// ensures that vital properties exist on fake request objects
function scaffoldReq(req) {
if (!req.headers) {

View File

@ -793,6 +793,8 @@ class Server {
const symbolicatingLogEntry =
log(createActionStartEntry('Symbolicating'));
debug('Start symbolication');
/* $FlowFixMe: where is `rowBody` defined? Is it added by
* the `connect` framework? */
Promise.resolve(req.rawBody).then(body => {
@ -842,6 +844,7 @@ class Server {
});
}).then(
stack => {
debug('Symbolication done');
res.end(JSON.stringify({stack: stack}));
process.nextTick(() => {
log(createActionEndEntry(symbolicatingLogEntry));
@ -918,6 +921,7 @@ class Server {
} {
// `true` to parse the query param as an object.
const urlObj = url.parse(reqUrl, true);
/* $FlowFixMe: `pathname` could be empty for an invalid URL */
const pathname = decodeURIComponent(urlObj.pathname);
@ -931,9 +935,6 @@ class Server {
return true;
}).join('.') + '.js';
const sourceMapUrlObj = Object.assign({}, urlObj);
sourceMapUrlObj.pathname = pathname.replace(/\.bundle$/, '.map');
// try to get the platform from the url
/* $FlowFixMe: `query` could be empty for an invalid URL */
const platform = urlObj.query.platform ||
@ -948,7 +949,12 @@ class Server {
const dev = this._getBoolOptionFromQuery(urlObj.query, 'dev', true);
const minify = this._getBoolOptionFromQuery(urlObj.query, 'minify', false);
return {
sourceMapUrl: url.format(sourceMapUrlObj),
sourceMapUrl: url.format({
hash: urlObj.hash,
pathname: pathname.replace(/\.bundle$/, '.map'),
query: urlObj.query,
search: urlObj.search,
}),
entryFile: entryFile,
dev,
minify,