Load playground.html etc. from local http server

Unlike goog.provide packages, goog.module modules are loaded using
XMLHttpRequest in uncompiled mode.  Because browsers treat file: URLs
as each being a separate, unique origin, this means that CORS rules
prevent goog.module modules being loaded from a file URL.

To work around this, use the http-server npm to serve the repository
root directory on localhost:8080.

Provide a script so that you can type `npm start` to start the local
http server and automatically open a browser window pointing at
tests/playground.html.

Modify the setBackgroundColour function in the playgrounds to provide
the usual lilac background on locahost URLs and a sickly green one
if using a file: URL, all of which will soon stop working.

(The background doesn't actually appear to be visible in the advanced
playground.)
This commit is contained in:
Christopher Allen
2021-07-09 16:07:36 +01:00
committed by Christopher Allen
parent b2490c57b8
commit 1306e41d3b
4 changed files with 161 additions and 7 deletions

View File

@@ -172,10 +172,14 @@ function initPlayground() {
}
function setBackgroundColour() {
// Set background colour to differentiate server vs local copy.
// Set background colour to differentiate file: vs. localhost
// vs. server copy.
if (location.protocol == 'file:') {
var lilac = '#d6d6ff';
document.body.style.backgroundColor = lilac;
document.body.style.backgroundColor = '#89A203'; // Unpleasant green.
} else if (location.hostname === 'localhost' ||
location.hostname === '127.0.0.1' ||
location.hostname === '[::1]') {
document.body.style.backgroundColor = '#d6d6ff'; // Familliar lilac.
}
}