client: Some minor fixups to base URL feature
* Cleanup cookie storage path * Cleanup Data URL
This commit is contained in:
parent
565027269c
commit
cbf67587e2
3 changed files with 17 additions and 6 deletions
|
@ -80,9 +80,8 @@ and Docker Compose (version 1.6.0 or greater) already installed.
|
||||||
Some users may wish to access the service at a different base URI, such
|
Some users may wish to access the service at a different base URI, such
|
||||||
as `http://example.com/szuru/`, commonly when sharing multiple HTTP
|
as `http://example.com/szuru/`, commonly when sharing multiple HTTP
|
||||||
services on one domain using a reverse proxy. In this case, simply set
|
services on one domain using a reverse proxy. In this case, simply set
|
||||||
`BASE_URL="/szuru/"` in the frontend container, and
|
`BASE_URL="/szuru/"` in the frontend container (unless you are hosting your
|
||||||
`DATA_URL="/szuru/data/"` in the backend container (unless you are hosting
|
data on a different domain).
|
||||||
your data on a different domain).
|
|
||||||
|
|
||||||
You should set your reverse proxy to proxy `http(s)://example.com/szuru` to
|
You should set your reverse proxy to proxy `http(s)://example.com/szuru` to
|
||||||
`http://<internal IP or hostname of frontend container>/`. For an NGINX
|
`http://<internal IP or hostname of frontend container>/`. For an NGINX
|
||||||
|
|
|
@ -9,6 +9,18 @@ const uri = require('./util/uri.js');
|
||||||
let fileTokens = {};
|
let fileTokens = {};
|
||||||
let remoteConfig = null;
|
let remoteConfig = null;
|
||||||
|
|
||||||
|
function getCookieName() {
|
||||||
|
const bases = document.getElementsByTagName('base');
|
||||||
|
if (bases.length) {
|
||||||
|
let baseHref = bases[0].href;
|
||||||
|
baseHref = baseHref.replace('/', '');
|
||||||
|
return 'szuru-' + baseHref;
|
||||||
|
} else {
|
||||||
|
return 'szuru';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const cookieName = getCookieName();
|
||||||
|
|
||||||
class Api extends events.EventTarget {
|
class Api extends events.EventTarget {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
@ -126,7 +138,7 @@ class Api extends events.EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
loginFromCookies() {
|
loginFromCookies() {
|
||||||
const auth = cookies.getJSON('auth');
|
const auth = cookies.getJSON(cookieName);
|
||||||
return auth && auth.user && auth.token ?
|
return auth && auth.user && auth.token ?
|
||||||
this.loginWithToken(auth.user, auth.token, true) :
|
this.loginWithToken(auth.user, auth.token, true) :
|
||||||
Promise.resolve();
|
Promise.resolve();
|
||||||
|
@ -169,7 +181,7 @@ class Api extends events.EventTarget {
|
||||||
this.post('/user-token/' + userName, userTokenRequest)
|
this.post('/user-token/' + userName, userTokenRequest)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
cookies.set(
|
cookies.set(
|
||||||
'auth',
|
cookieName,
|
||||||
{'user': userName, 'token': response.token},
|
{'user': userName, 'token': response.token},
|
||||||
options);
|
options);
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
|
|
|
@ -28,7 +28,7 @@ def docker_config() -> Dict:
|
||||||
return {
|
return {
|
||||||
'debug': True,
|
'debug': True,
|
||||||
'show_sql': int(os.getenv('LOG_SQL', 0)),
|
'show_sql': int(os.getenv('LOG_SQL', 0)),
|
||||||
'data_url': os.getenv('DATA_URL', '/data/'),
|
'data_url': os.getenv('DATA_URL', 'data/'),
|
||||||
'data_dir': '/data/',
|
'data_dir': '/data/',
|
||||||
'database': 'postgres://%(user)s:%(pass)s@%(host)s:%(port)d/%(db)s' % {
|
'database': 'postgres://%(user)s:%(pass)s@%(host)s:%(port)d/%(db)s' % {
|
||||||
'user': os.getenv('POSTGRES_USER'),
|
'user': os.getenv('POSTGRES_USER'),
|
||||||
|
|
Loading…
Reference in a new issue