-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix #3372 check for valid server #3392
Changes from all commits
426bfa3
2a3f8b8
a4006f2
90e749f
8bb9626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,6 +296,12 @@ define(function LiveDevelopment(require, exports, module) { | |
_liveDocument.close(); | ||
_liveDocument = undefined; | ||
} | ||
|
||
if (_serverProvider) { | ||
// Remove any "request" listeners that were added previously | ||
$(_serverProvider).off(".livedev"); | ||
} | ||
|
||
if (_relatedDocuments) { | ||
_relatedDocuments.forEach(function (liveDoc) { | ||
liveDoc.close(); | ||
|
@@ -315,13 +321,43 @@ define(function LiveDevelopment(require, exports, module) { | |
} | ||
} | ||
|
||
/** Open a live document | ||
/** | ||
* @private | ||
* Open a live document | ||
* @param {Document} source document to open | ||
* @return {jQuery.Promise} A promise that is resolved once the live | ||
* document is open, and is never explicitly rejected. | ||
*/ | ||
function _openDocument(doc, editor) { | ||
_closeDocument(); | ||
_liveDocument = _createDocument(doc, editor); | ||
|
||
// Enable instrumentation | ||
if (_liveDocument.setInstrumentationEnabled) { | ||
var enableInstrumentation = false; | ||
|
||
if (_serverProvider && _serverProvider.setRequestFilterPaths) { | ||
enableInstrumentation = true; | ||
|
||
_serverProvider.setRequestFilterPaths( | ||
["/" + encodeURI(ProjectManager.makeProjectRelativeIfPossible(doc.file.fullPath))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug fix for paths like |
||
); | ||
|
||
// Send custom HTTP response for the current live document | ||
$(_serverProvider).on("request.livedev", function (event, request) { | ||
// response can be null in which case the StaticServerDomain reverts to simple file serving. | ||
var response = _liveDocument.getResponseData ? _liveDocument.getResponseData() : null; | ||
request.send(response); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a good comment to put in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
}); | ||
} | ||
|
||
_liveDocument.setInstrumentationEnabled(enableInstrumentation); | ||
} | ||
} | ||
|
||
/** | ||
* @private | ||
* Populate array of related documents reported by the browser agent(s) | ||
*/ | ||
function _getRelatedDocuments() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate related documents from the current document ( |
||
function createLiveStylesheet(url) { | ||
var stylesheetDeferred = $.Deferred(); | ||
|
||
|
@@ -348,9 +384,6 @@ define(function LiveDevelopment(require, exports, module) { | |
return stylesheetDeferred.promise(); | ||
} | ||
|
||
_closeDocument(); | ||
_liveDocument = _createDocument(doc, editor); | ||
|
||
// Gather related CSS documents. | ||
// FUTURE: Gather related JS documents as well. | ||
_relatedDocuments = []; | ||
|
@@ -453,13 +486,12 @@ define(function LiveDevelopment(require, exports, module) { | |
return; | ||
} | ||
|
||
var editor = EditorManager.getCurrentFullEditor(), | ||
status = STATUS_ACTIVE; | ||
var status = STATUS_ACTIVE; | ||
|
||
// Note: the following promise is never explicitly rejected, so there | ||
// is no failure handler. If _openDocument is changed so that rejection | ||
// is no failure handler. If _getRelatedDocuments is changed so that rejection | ||
// is possible, failure should be managed accordingly. | ||
_openDocument(doc, editor) | ||
_getRelatedDocuments() | ||
.done(function () { | ||
if (doc.isDirty && _classForDocument(doc) !== CSSDocument) { | ||
status = STATUS_OUT_OF_SYNC; | ||
|
@@ -572,23 +604,7 @@ define(function LiveDevelopment(require, exports, module) { | |
function doLaunchAfterServerReady() { | ||
_setStatus(STATUS_CONNECTING); | ||
|
||
if (_serverProvider) { | ||
// Install a request filter for the current document. In the future, | ||
// we need to install filters for *all* files that need to be instrumented. | ||
HTMLInstrumentation.scanDocument(doc); | ||
_serverProvider.setRequestFilterPaths( | ||
["/" + ProjectManager.makeProjectRelativeIfPossible(doc.file.fullPath)] | ||
); | ||
|
||
// Remove any "request" listeners that were added previously | ||
$(_serverProvider).off(".livedev"); | ||
|
||
$(_serverProvider).on("request.livedev", function (event, request) { | ||
var html = HTMLInstrumentation.generateInstrumentedHTML(doc); | ||
|
||
request.send({ body: html }); | ||
}); | ||
} | ||
_openDocument(doc, EditorManager.getCurrentFullEditor()); | ||
|
||
Inspector.connectToURL(launcherUrl).done(result.resolve).fail(function onConnectFail(err) { | ||
if (err === "CANCEL") { | ||
|
@@ -669,7 +685,6 @@ define(function LiveDevelopment(require, exports, module) { | |
|
||
if (!doc || !doc.root) { | ||
showWrongDocError(); | ||
|
||
} else { | ||
_serverProvider = LiveDevServerManager.getProvider(doc.file.fullPath); | ||
|
||
|
@@ -841,9 +856,9 @@ define(function LiveDevelopment(require, exports, module) { | |
if (Inspector.connected()) { | ||
hideHighlight(); | ||
if (agents.network && agents.network.wasURLRequested(doc.url)) { | ||
_closeDocument(); | ||
var editor = EditorManager.getCurrentFullEditor(); | ||
promise = _openDocument(doc, editor); | ||
_openDocument(doc, EditorManager.getCurrentFullEditor()); | ||
|
||
promise = _getRelatedDocuments(); | ||
} else { | ||
if (exports.config.experimental || _isHtmlFileExt(doc.extension)) { | ||
promise = close().done(open); | ||
|
@@ -895,15 +910,10 @@ define(function LiveDevelopment(require, exports, module) { | |
|
||
/** | ||
* Determines whether we can serve local file. | ||
* | ||
* @param {String} localPath | ||
* A local path to file being served. | ||
* | ||
* @return {Boolean} | ||
* true for yes, otherwise false. | ||
* @param {String} localPath A local path to file being served. | ||
* @return {Boolean} true for yes, otherwise false. | ||
*/ | ||
UserServerProvider.prototype.canServe = function (localPath) { | ||
|
||
var baseUrl = ProjectManager.getBaseUrl(); | ||
if (!baseUrl) { | ||
return false; | ||
|
@@ -918,9 +928,7 @@ define(function LiveDevelopment(require, exports, module) { | |
|
||
/** | ||
* Returns a base url for current project. | ||
* | ||
* @return {String} | ||
* Base url for current project. | ||
* @return {String} Base url for current project. | ||
*/ | ||
UserServerProvider.prototype.getBaseUrl = function () { | ||
return ProjectManager.getBaseUrl(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Primary fix for #3372 to check for
setRequestFilterPaths
.