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.
This commit is contained in:
parent
bd9db332d2
commit
38ba9f9187
|
@ -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);
|
||||
}
|
||||
|
|
57
server.js
57
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user