Support dynamic route
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
1671719c25
commit
0cca633542
@ -266,7 +266,7 @@ app.use(basePath + "api/v1/albums", require("./routes/albums"));
|
||||
app.use(basePath + "api/v1/scan", require("./routes/scan")(scanner));
|
||||
|
||||
/* Declare the "catch all" index route last; the final route is a 404 dynamic router */
|
||||
app.use(basePath + "/*", index);
|
||||
app.use(basePath, index);
|
||||
|
||||
/**
|
||||
* Create HTTP server and listen for new connections
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
const express = require("express"),
|
||||
fs = require("fs"),
|
||||
url = require("url"),
|
||||
config = require("config");
|
||||
url = require("url");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@ -30,13 +29,24 @@ const extensionMatch = new RegExp("^.*?(" + extensions.join("|") + ")$", "i");
|
||||
* If so, 404 because the asset isn't there. otherwise assume it is a
|
||||
* dynamic client side route and *then* return index.html.
|
||||
*/
|
||||
router.get("/", function(req, res/*, next*/) {
|
||||
router.get("/*", function(req, res, next) {
|
||||
const parts = url.parse(req.url),
|
||||
basePath = req.app.get("basePath");
|
||||
|
||||
console.log("Index check for " + req.url + " with user as " + req.user);
|
||||
|
||||
/* If req.user isn't set yet (authentication hasn't happened) then
|
||||
* only allow / to be loaded--everything else chains to the next
|
||||
* handler */
|
||||
if (!req.user && req.url != "/") {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (req.url == "/" || !extensionMatch.exec(parts.pathname)) {
|
||||
console.log("Returning index for " + req.url);
|
||||
|
||||
/* Replace <script>'<base href="/BASEPATH/">';</script> in index.html with
|
||||
* the basePath */
|
||||
* the basePath */
|
||||
const index = fs.readFileSync("frontend/index.html", "utf8");
|
||||
|
||||
res.send(index.replace(
|
||||
|
Loading…
x
Reference in New Issue
Block a user