start implementation of ui-scripts

This commit is contained in:
Sebastian Sdorra
2019-10-14 16:00:50 +02:00
parent 00117955e7
commit cab5d6c863
14 changed files with 357 additions and 391 deletions

View File

@@ -0,0 +1,11 @@
function crateContextPathMiddleware(contextPath) {
return function(req, resp, next) {
const url = req.url;
if (url.indexOf(contextPath) === 0) {
req.url = url.substr(contextPath.length);
}
next();
}
}
module.exports = crateContextPathMiddleware;

View File

@@ -0,0 +1,20 @@
const mustache = require("mustache");
const fs = require("fs");
// disable escaping
mustache.escape = function(text) {
return text;
};
function createIndexMiddleware(file, params) {
const template = fs.readFileSync(file, { encoding: "UTF-8" });
return function(req, resp, next) {
if (req.url === "/index.html") {
const content = mustache.render(template, params);
resp.send(content);
} else {
next();
}
}
}
module.exports = createIndexMiddleware;