Works under a nested path

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2020-02-09 22:38:52 -08:00
parent 324be24430
commit d562beef8e
5 changed files with 51 additions and 24 deletions

View File

@ -1,8 +1,8 @@
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="../frontend/icons-192.png" sizes="192x192">
<base href="/photos/">
<link rel="icon" href="./frontend/icons-192.png" sizes="192x192">
<base href="/chalk/">
<style>
body {
background-image: linear-gradient(#090B1A, #131524);

View File

@ -41,7 +41,7 @@
"googleapis": "^40.0.0",
"handlebars": "^4.7.2",
"jira-connector": "^2.10.0",
"ldapauth-fork": "^4.3.0",
"ldapauth-fork": "=4.2.0",
"ldapjs": "^1.0.2",
"mariasql": "^0.2.6",
"moment": "^2.24.0",

View File

@ -35,6 +35,7 @@ function ldapPromise(username, password) {
if (!ldap) {
return Promise.reject("LDAP not being used");
}
return new Promise(function(resolve, reject) {
ldap.authenticate(username.replace(/@.*$/, ""), password, function(error, user) {
if (error) {
@ -47,7 +48,6 @@ function ldapPromise(username, password) {
const ldapJS = require("ldapjs"),
ldapConfig = config.get("ldap");
const ldapSetPassword = function(username, password) {
const client = ldapJS.createClient({
@ -325,7 +325,8 @@ router.post("/login", function(req, res) {
req.session.userId = "LDAP";
req.session.ldapUser = user;
return user;
}).catch(function() {
}).catch(function(error) {
console.warn(error);
console.log("User not found in LDAP. Looking up in DB.");
let query = "SELECT " +
"id,mailVerified,authenticated,uid AS username,displayName AS name,mail " +

View File

@ -108,14 +108,22 @@ class App extends React.Component {
}
render() {
console.log("App");
const tmp = document.querySelector("base");
let base;
if (tmp) {
base = new URL(tmp.href).pathname.replace(/\/$/, "") + "/"; /* Make sure there is a trailing slash */
} else {
base = "/";
}
console.log("App: " + base);
return (
<div className="App" ref={ ref => (this.app = ref) }>
<Header/>
<div className="Body">
<div className="Main">
<Switch>
<Route path="/identities" render={ (props) => <Identities {...props}/> }/>
<Route path={ base + "identities" } render={ (props) => <Identities {...props}/> }/>
<Route path="/faces" render={ props => <div {...props}/> }/>
<Route path="/photos" render={ props => <div {...props}/> }/>
</Switch>
@ -258,6 +266,8 @@ function makeFaceBoxes(photo, photoExplorer) {
if (event.shiftKey) {
window.open("identities?face=" + face.id, "faceId-" + face.id);
} else {
const identitiesBlock = document.getElementById("identities");
identitiesBlock.innerHTML = "";
loadFace(face.id);
}
});
@ -425,6 +435,8 @@ function createUseThisIdentityButton(identityId) {
const button = document.createElement("button");
button.textContent = "Use this identity";
button.addEventListener("click", (event) => {
const identitiesBlock = document.getElementById("identities");
identitiesBlock.innerHTML = "";
const object = {
faces: []
};
@ -457,6 +469,8 @@ function createActionButtons() {
button = document.createElement("button");
button.textContent = "Load random face";
button.addEventListener("click", (event) => {
const identitiesBlock = document.getElementById("identities");
identitiesBlock.innerHTML = "";
loadFace();
});
buttonBlock.appendChild(button);
@ -472,6 +486,8 @@ function createActionButtons() {
},
body: JSON.stringify({ faceId: faceId })
}).then(res => res.json()).then(() => {
const identitiesBlock = document.getElementById("identities");
identitiesBlock.innerHTML = "";
loadFace();
});
});
@ -562,7 +578,9 @@ function createNewIdentityEditor() {
object.faces.push(face.getAttribute("face-id"));
}
});
window.fetch("api/v1/identities", {
const identitiesBlock = document.getElementById("identities");
identitiesBlock.innerHTML = "";
window.fetch("api/v1/identities", {
method: "POST",
headers: {
'Accept': 'application/json',
@ -579,6 +597,8 @@ function createNewIdentityEditor() {
});
const face = document.body.querySelector("#face-editor .face"),
faceId = parseInt(face.getAttribute("face-id"));
const identitiesBlock = document.getElementById("identities");
identitiesBlock.innerHTML = "";
loadFace(faceId);
getIdentities(faceId);
});
@ -586,4 +606,4 @@ function createNewIdentityEditor() {
block.appendChild(editor);
return block;
}
}

View File

@ -2,30 +2,36 @@ const path = require("path");
const merge = require('webpack-merge')
const common = require('./webpack.common.js');
const webpack = require('webpack');
const config = require('config');
const base = config.get("basePath");
const proxy = {
// "/photos/api/*": "http://localhost:8123/",
}
proxy[`${base}/`] = {
target: "http://localhost:8766",
bypass: function(req, res, proxyOptions) {
console.log(req.url);
if (req.url.match(new RegExp(base.replace(/\//g, "\\/") + "\/identities[/?]?"))) {
return 'index.html';
} else {
return null;
}
}
};
module.exports = merge(common, {
mode: "development",
devServer: {
contentBase: path.join(__dirname, "/"),
port: 8765,
publicPath: "http://localhost:8765/photos/dist/",
publicPath: `http://localhost:8765${base}/dist/`,
hotOnly: true,
disableHostCheck: true,
historyApiFallback: true,
proxy: {
// "/photos/api/*": "http://localhost:8123/",
"/photos/": {
target: "http://localhost:8123",
bypass: function(req, res, proxyOptions) {
console.log(req.url);
if (req.url.match(/^\/photos\/identities[/?]?/)) {
return 'index.html';
} else {
return null;
}
}
}
},
proxy: proxy
},
plugins: [new webpack.HotModuleReplacementPlugin()]
});