From cbf67587e29565a4783a49c506f23b2e5cfe49d0 Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Fri, 17 Aug 2018 23:09:13 -0400 Subject: [PATCH] client: Some minor fixups to base URL feature * Cleanup cookie storage path * Cleanup Data URL --- INSTALL.md | 5 ++--- client/js/api.js | 16 ++++++++++++++-- server/szurubooru/config.py | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 7fb94666..6465235e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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 as `http://example.com/szuru/`, commonly when sharing multiple HTTP services on one domain using a reverse proxy. In this case, simply set - `BASE_URL="/szuru/"` in the frontend container, and - `DATA_URL="/szuru/data/"` in the backend container (unless you are hosting - your data on a different domain). + `BASE_URL="/szuru/"` in the frontend container (unless you are hosting your + data on a different domain). You should set your reverse proxy to proxy `http(s)://example.com/szuru` to `http:///`. For an NGINX diff --git a/client/js/api.js b/client/js/api.js index 07ec5ec9..c8e571c5 100644 --- a/client/js/api.js +++ b/client/js/api.js @@ -9,6 +9,18 @@ const uri = require('./util/uri.js'); let fileTokens = {}; 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 { constructor() { super(); @@ -126,7 +138,7 @@ class Api extends events.EventTarget { } loginFromCookies() { - const auth = cookies.getJSON('auth'); + const auth = cookies.getJSON(cookieName); return auth && auth.user && auth.token ? this.loginWithToken(auth.user, auth.token, true) : Promise.resolve(); @@ -169,7 +181,7 @@ class Api extends events.EventTarget { this.post('/user-token/' + userName, userTokenRequest) .then(response => { cookies.set( - 'auth', + cookieName, {'user': userName, 'token': response.token}, options); this.userName = userName; diff --git a/server/szurubooru/config.py b/server/szurubooru/config.py index b2f593d6..f9c745ca 100644 --- a/server/szurubooru/config.py +++ b/server/szurubooru/config.py @@ -28,7 +28,7 @@ def docker_config() -> Dict: return { 'debug': True, '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/', 'database': 'postgres://%(user)s:%(pass)s@%(host)s:%(port)d/%(db)s' % { 'user': os.getenv('POSTGRES_USER'),