www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 38ba9f91877cdbc3b687de16803c41d6fffafb74
parent bd9db332d2887d884ec7ab3ca68488314b8618da
Author: Martin von Gagern <gagern@ma.tum.de>
Date:   Tue, 10 Jan 2017 14:28:23 +0100

Serve files with and without babelify step

As babelify is slow, it may be desriable to not run it during development.
This is OK if the browser is recent enough to understand ES6 natively.
(This does not include current Firefox due to it having problems with
for(const … in …), https://bugzilla.mozilla.org/show_bug.cgi?id=1094995.)
For older browsers, or to check issues possibly introduced by babelify,
adding /babel as the first component of the path will switch to a version
which has been processed by babelify.  This is also used for screenshots.

Diffstat:
Mdockers/Screenshotter/screenshotter.js | 4++--
Mserver.js | 61+++++++++++++++++++++++++++++++++++--------------------------
Mtest/screenshotter/test.html | 4++--
3 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/dockers/Screenshotter/screenshotter.js b/dockers/Screenshotter/screenshotter.js @@ -291,7 +291,7 @@ function findHostIP() { } if (katexIP !== "*any*" || katexURL) { if (!katexURL) { - katexURL = "http://" + katexIP + ":" + katexPort + "/"; + katexURL = "http://" + katexIP + ":" + katexPort + "/babel/"; console.log("KaTeX URL is " + katexURL); } process.nextTick(takeScreenshots); @@ -303,7 +303,7 @@ function findHostIP() { app.get("/ss-connect.js", function(req, res, next) { if (!katexURL) { katexIP = req.query.ip; - katexURL = "http://" + katexIP + ":" + katexPort + "/"; + katexURL = "http://" + katexIP + ":" + katexPort + "/babel/"; console.log("KaTeX URL is " + katexURL); process.nextTick(takeScreenshots); } diff --git a/server.js b/server.js @@ -15,7 +15,7 @@ if (require.main === module) { ":date[iso] :method :url HTTP/:http-version - :status")); } -var serveBrowserified = function(file, standaloneName) { +function serveBrowserified(file, standaloneName, doBabelify) { return function(req, res, next) { let files; if (Array.isArray(file)) { @@ -26,9 +26,10 @@ var serveBrowserified = function(file, standaloneName) { files = [path.join(__dirname, file)]; } - const options = { - transform: [babelify] - }; + const options = {}; + if (doBabelify) { + options.transform = [babelify]; + } if (standaloneName) { options.standalone = standaloneName; } @@ -43,22 +44,32 @@ var serveBrowserified = function(file, standaloneName) { res.send(body); }); }; -}; - -app.get("/katex.js", serveBrowserified("katex", "katex")); -app.use("/test/jasmine", - express["static"]( - path.dirname( - require.resolve("jasmine-core/lib/jasmine-core/jasmine.js") - ) - ) -); -app.get("/test/katex-spec.js", serveBrowserified("test/*[Ss]pec.js")); -app.get("/contrib/auto-render/auto-render.js", - serveBrowserified("contrib/auto-render/auto-render", - "renderMathInElement")); - -app.get("/katex.css", function(req, res, next) { +} + +function twoBrowserified(url, file, standaloneName) { + app.get(url, serveBrowserified(file, standaloneName, false)); + app.get("/babel" + url, serveBrowserified(file, standaloneName, true)); +} + +function twoUse(url, handler) { + app.use(url, handler); + app.use("/babel" + url, handler); +} + +function twoStatic(url, file) { + twoUse(url, express.static(path.join(__dirname, file))); +} + +twoBrowserified("/katex.js", "katex", "katex"); +twoUse("/test/jasmine", express.static(path.dirname( + require.resolve("jasmine-core/lib/jasmine-core/jasmine.js")))); +twoBrowserified("/test/katex-spec.js", "test/*[Ss]pec.js"); +twoBrowserified( + "/contrib/auto-render/auto-render.js", + "contrib/auto-render/auto-render", + "renderMathInElement"); + +twoUse("/katex.css", function(req, res, next) { const lessfile = path.join(__dirname, "static", "katex.less"); fs.readFile(lessfile, {encoding: "utf8"}, function(err, data) { if (err) { @@ -82,12 +93,10 @@ app.get("/katex.css", function(req, res, next) { }); }); -app.use(express["static"](path.join(__dirname, "static"))); -app.use(express["static"](path.join(__dirname, "build"))); -app.use("/test", express["static"](path.join(__dirname, "test"))); -app.use("/contrib", express["static"](path.join(__dirname, "contrib"))); -// app.use("/unicode-fonts", -// express["static"](path.join(__dirname, "static", "unicode-fonts"))); +twoStatic("", "static"); +twoStatic("", "build"); +twoStatic("/test", "test"); +twoStatic("/contrib", "contrib"); app.use(function(err, req, res, next) { console.error(err.stack); diff --git a/test/screenshotter/test.html b/test/screenshotter/test.html @@ -2,8 +2,8 @@ <html> <head> <title>Screenshotter test</title> - <script src="/katex.js" type="text/javascript"></script> - <link href="/katex.css" rel="stylesheet" type="text/css"> + <script src="../../katex.js" type="text/javascript"></script> + <link href="../../katex.css" rel="stylesheet" type="text/css"> <style type="text/css"> #math, #pre, #post { font-size: 4em;