Added basepath scanner
Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
This commit is contained in:
parent
39f87a596f
commit
b91ba94439
33
server/routes/basepath.js
Normal file
33
server/routes/basepath.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const express = require("express"),
|
||||||
|
fs = require("fs"),
|
||||||
|
url = require("url");
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
/* This router only handles HTML files and is used
|
||||||
|
* to replace BASEPATH */
|
||||||
|
router.get("/*", function(req, res, next) {
|
||||||
|
const parts = url.parse(req.url),
|
||||||
|
basePath = req.app.get("basePath");
|
||||||
|
|
||||||
|
if (!/\/[^/]+\.html$/.exec(parts.pathname)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Attempting to parse 'frontend" + parts.pathname + "'");
|
||||||
|
|
||||||
|
/* Replace <script>'<base href="/BASEPATH/">';</script> in index.html with
|
||||||
|
* the basePath */
|
||||||
|
fs.readFile("frontend" + parts.pathname, "utf8", function(error, content) {
|
||||||
|
if (error) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
res.send(content.replace(
|
||||||
|
/<script>'<base href="BASEPATH">';<\/script>/,
|
||||||
|
"<base href='" + basePath + "'>"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
Loading…
x
Reference in New Issue
Block a user