diff --git a/dockers/Screenshotter/screenshotter.js b/dockers/Screenshotter/screenshotter.js index 968a717..045813e 100644 --- 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 index 9a2b47a..c7a1ae3 100644 --- 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")); +function twoBrowserified(url, file, standaloneName) { + app.get(url, serveBrowserified(file, standaloneName, false)); + app.get("/babel" + url, serveBrowserified(file, standaloneName, true)); +} -app.get("/katex.css", function(req, res, next) { +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 index 3694ba9..4d9745f 100644 --- a/test/screenshotter/test.html +++ b/test/screenshotter/test.html @@ -2,8 +2,8 @@