Inject <base> into pages managed via routes/index.js
Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
This commit is contained in:
parent
6202b833f0
commit
821c10816a
@ -2,7 +2,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<link rel="icon" href="./frontend/icons-192.png" sizes="192x192">
|
<link rel="icon" href="./frontend/icons-192.png" sizes="192x192">
|
||||||
<base href="/photos/">
|
<script>'<base href="BASEPATH">';</script>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-image: linear-gradient(#090B1A, #131524);
|
background-image: linear-gradient(#090B1A, #131524);
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
"description": "Self hosting photo",
|
"description": "Self hosting photo",
|
||||||
"main": "server/app.js",
|
"main": "server/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./server/app.js",
|
"start": "npm server",
|
||||||
|
"start-devel": "concurrently \"npm:server\" \"npm:dev\"",
|
||||||
|
"server": "node ./server/app.js",
|
||||||
"faces": "node ./server/face-recognizer.js",
|
"faces": "node ./server/face-recognizer.js",
|
||||||
"dev": "webpack-dev-server --mode development --host 0.0.0.0 --config webpack.dev.js",
|
"dev": "webpack-dev-server --mode development --host 0.0.0.0 --config webpack.dev.js",
|
||||||
"build": "webpack --config webpack.prod.js",
|
"build": "webpack --config webpack.prod.js",
|
||||||
@ -31,6 +33,7 @@
|
|||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"bootstrap": "^4.4.1",
|
"bootstrap": "^4.4.1",
|
||||||
"canvas": "^2.6.1",
|
"canvas": "^2.6.1",
|
||||||
|
"concurrently": "^5.1.0",
|
||||||
"config": "^3.2.4",
|
"config": "^3.2.4",
|
||||||
"connect-sqlite3": "^0.9.11",
|
"connect-sqlite3": "^0.9.11",
|
||||||
"cookie-parser": "^1.4.4",
|
"cookie-parser": "^1.4.4",
|
||||||
|
@ -40,17 +40,32 @@ router.get("/*", function(req, res, next) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.url == "/" || !extensionMatch.exec(parts.pathname)) {
|
if (extensionMatch.exec(parts.pathname)) {
|
||||||
console.log("Returning index for " + req.url);
|
return res.status(404).send({
|
||||||
|
message: "File not found",
|
||||||
|
status: 404
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let source;
|
||||||
|
switch (req.url) {
|
||||||
|
case "/":
|
||||||
|
source = "frontend/index.html";
|
||||||
|
break;
|
||||||
|
case "/identities":
|
||||||
|
source = "./index.html";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source) {
|
||||||
|
console.log("Returning " + source + " for " + req.url);
|
||||||
/* Replace <script>'<base href="/BASEPATH/">';</script> in index.html with
|
/* Replace <script>'<base href="/BASEPATH/">';</script> in index.html with
|
||||||
* the basePath */
|
* the basePath */
|
||||||
const index = fs.readFileSync("frontend/index.html", "utf8");
|
const index = fs.readFileSync(source, "utf8");
|
||||||
|
|
||||||
res.send(index.replace(
|
return res.send(index.replace(
|
||||||
/<script>'<base href="BASEPATH">';<\/script>/,
|
/<script>'<base href="BASEPATH">';<\/script>/,
|
||||||
"<base href='" + basePath + "'>"));
|
"<base href='" + basePath + "'>"));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Page not found: " + req.url);
|
console.log("Page not found: " + req.url);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user