mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-03-31 06:24:02 -04:00
Fixed missing x-ingress-path within authorization.js redirects. Implemented local/development .options.json config
This commit is contained in:
@@ -12,6 +12,9 @@ npm-debug.log
|
||||
# Build files
|
||||
public/dist/
|
||||
|
||||
# Local config
|
||||
.options.json
|
||||
|
||||
# Project files
|
||||
.github
|
||||
.editorconfig
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,3 +11,6 @@ npm-debug.log
|
||||
|
||||
# Build files
|
||||
public/dist/
|
||||
|
||||
# Local config
|
||||
.options.json
|
||||
|
||||
@@ -27,7 +27,7 @@ module.exports = {
|
||||
if(!authDisabled) {
|
||||
// Check if user has an existing authorization cookie
|
||||
if (!req.cookies.authorization) {
|
||||
res.redirect(302, '/login');
|
||||
res.redirect(302, `${req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : ''}/login`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ module.exports = {
|
||||
const check = jwt.verify(req.cookies.authorization);
|
||||
|
||||
if(!check) {
|
||||
res.cookie('flashMessage', JSON.stringify({type: 'error', message: 'Invalid or expired login!'}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, '/login');
|
||||
res.cookie('flashMessage', JSON.stringify({type: 'error', message: 'Invalid or expired login!'}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, `${req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : ''}/login`);
|
||||
}
|
||||
} catch (e) {
|
||||
res.cookie('flashMessage', JSON.stringify({type: 'error', message: 'Invalid or expired login!'}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, '/login');
|
||||
res.cookie('flashMessage', JSON.stringify({type: 'error', message: 'Invalid or expired login!'}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, `${req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : ''}/login`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,20 @@
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* Get an option from external config (Home Assistant)
|
||||
* Get an option from external config (Home Assistant / Local Development)
|
||||
*
|
||||
* @param option
|
||||
*/
|
||||
module.exports = (option) => {
|
||||
// Check if Home Assistant config exists
|
||||
if (fs.existsSync('/data/options.json')) {
|
||||
return JSON.parse(fs.readFileSync('/data/options.json', 'utf-8'))[option];
|
||||
}
|
||||
|
||||
// Check if Local (Development) config exists
|
||||
if (fs.existsSync(`${__dirname}/../.options.json`)) {
|
||||
return JSON.parse(fs.readFileSync(`${__dirname}/../.options.json`, 'utf-8'))[option];
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -70,6 +70,9 @@ if(fs.existsSync('/etc/unifi_voucher_site_build')) {
|
||||
if (fs.existsSync('/data/options.json')) {
|
||||
log.info('[Options] Found at /data/options.json');
|
||||
}
|
||||
if (fs.existsSync(`${__dirname}/.options.json`)) {
|
||||
log.info(`[Options] Found at ${__dirname}/.options.json`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log service status
|
||||
|
||||
Reference in New Issue
Block a user