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));
|
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 */
|
/* 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
|
* Create HTTP server and listen for new connections
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
const express = require("express"),
|
const express = require("express"),
|
||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
url = require("url"),
|
url = require("url");
|
||||||
config = require("config");
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@ -30,11 +29,22 @@ const extensionMatch = new RegExp("^.*?(" + extensions.join("|") + ")$", "i");
|
|||||||
* If so, 404 because the asset isn't there. otherwise assume it is a
|
* If so, 404 because the asset isn't there. otherwise assume it is a
|
||||||
* dynamic client side route and *then* return index.html.
|
* 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),
|
const parts = url.parse(req.url),
|
||||||
basePath = req.app.get("basePath");
|
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)) {
|
if (req.url == "/" || !extensionMatch.exec(parts.pathname)) {
|
||||||
|
console.log("Returning index 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("frontend/index.html", "utf8");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user