mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 05:55:44 +01:00
start implementation of ui-scripts
This commit is contained in:
11
scm-ui/ui-scripts/src/middleware/ContextPathMiddleware.js
Normal file
11
scm-ui/ui-scripts/src/middleware/ContextPathMiddleware.js
Normal 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;
|
||||
20
scm-ui/ui-scripts/src/middleware/IndexMiddleware.js
Normal file
20
scm-ui/ui-scripts/src/middleware/IndexMiddleware.js
Normal 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;
|
||||
Reference in New Issue
Block a user