Skip to content

Commit

Permalink
Fix missing require reference in shims/nohost.js
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Apr 11, 2014
1 parent 747072a commit 3e2a5ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 11 additions & 2 deletions shims/nohost.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* The nohost.js shim is the first thing loaded by any page
* being served from the nohost server (ie., it gets injected
* before all other scripts). It is used to alter the environment
* so dynamic changes requiring data from the filesystem will
* continue to work in the nohost served page.
*/
var nohost = (function(window) {

// The server's filesystem
Expand Down Expand Up @@ -58,7 +65,7 @@ var nohost = (function(window) {
window.Image = Image;
}

// Alter <img> to intercept paths in the filesystem
// Alter <script> to intercept paths in the filesystem
function rewireScript() {
var $Image = window.Image;

Expand All @@ -81,7 +88,7 @@ var nohost = (function(window) {

// Alter XMLHttpRequest so it knows about nohost files
function rewireXHR() {
require(['xhr']);
window.XMLHttpRequest = require('xhr');
}

// Setup auto-reload behaviour for watched paths
Expand Down Expand Up @@ -133,6 +140,8 @@ var nohost = (function(window) {
rewireImage();
rewireXHR();
startWatchers();

// Do this last, so we don't lose require while we still need it
cleanEnv();
}

Expand Down
2 changes: 1 addition & 1 deletion shims/xmlhttprequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ define(['filer'], function(Filer) {
return self;
}

window.XMLHttpRequest = $XMLHttpRequest;
return $XMLHttpRequest;

});
8 changes: 2 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requirejs.config({
}
});

requirejs(['filer', 'webserver'], function(Filer, WebServer) {
requirejs(['filer', 'webserver', 'xhr'], function(Filer, WebServer) {
var Path = Filer.Path;

function install(file) {
Expand Down Expand Up @@ -89,11 +89,7 @@ requirejs(['filer', 'webserver'], function(Filer, WebServer) {
// Case 3: a path was given into the web root, try to serve it.
// Strip any server added trailing slash (unless we have '/').
var url = option === '/' ? option : option.replace(/\/$/, '');

// We need to swap out the XHR implementation when loading from the filesystem
require(['xhr'], function() {
WebServer.serve(url);
});
WebServer.serve(url);
}

boot();
Expand Down

0 comments on commit 3e2a5ed

Please sign in to comment.