From a524f1faf38c128eb8dabdfeef1fbcdc23ae223d Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 3 Dec 2019 23:18:14 +0200 Subject: add configurable URL prefix --- README.md | 7 +++++++ app/main.py | 23 ++++++++++++++++++----- favicon/browserconfig.xml | 2 +- favicon/site.webmanifest | 4 ++-- ui/src/index.html | 15 +++++++-------- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8e5f3ed..4776304 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,13 @@ services: - /path/to/downloads:/downloads ``` +## Configuration via environment variables + +Certain values can be set via environment variables, using the `-e` parameter on the docker command line, or the `environment:` section in docker-compose. + +* __DOWNLOAD_DIR__: path to where the downloads will be saved. Defaults to "/downloads" in the docker image, and "." otherwise. +* __URL_PREFIX__: base path for the web server (for use when hosting behind a reverse proxy). Defaults to "/". + ## Build and run locally Make sure you have node.js installed. diff --git a/app/main.py b/app/main.py index 4c48aeb..7031055 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=no-member,method-hidden import os from aiohttp import web @@ -15,6 +16,7 @@ log = logging.getLogger('main') class Config: _DEFAULTS = { 'DOWNLOAD_DIR': '.', + 'URL_PREFIX': '', } def __init__(self): @@ -35,6 +37,8 @@ app = web.Application() sio = socketio.AsyncServer() sio.attach(app) routes = web.RouteTableDef() +if not config.URL_PREFIX.endswith('/'): + config.URL_PREFIX += '/' class Notifier(DownloadQueueNotifier): async def added(self, dl): @@ -54,7 +58,7 @@ class Notifier(DownloadQueueNotifier): dqueue = DownloadQueue(config, Notifier()) -@routes.post('/add') +@routes.post(config.URL_PREFIX + 'add') async def add(request): post = await request.json() url = post.get('url') @@ -63,7 +67,7 @@ async def add(request): status = await dqueue.add(url) return web.Response(text=serializer.encode(status)) -@routes.post('/delete') +@routes.post(config.URL_PREFIX + 'delete') async def delete(request): post = await request.json() ids = post.get('ids') @@ -77,12 +81,21 @@ async def delete(request): async def connect(sid, environ): await sio.emit('all', serializer.encode(dqueue.get()), to=sid) -@routes.get('/') +@routes.get(config.URL_PREFIX) def index(request): return web.FileResponse('ui/dist/metube/index.html') -routes.static('/favicon/', 'favicon') -routes.static('/', 'ui/dist/metube') +if config.URL_PREFIX != '/': + @routes.get('/') + def index_redirect_root(request): + return web.HTTPFound(config.URL_PREFIX) + + @routes.get(config.URL_PREFIX[:-1]) + def index_redirect_dir(request): + return web.HTTPFound(config.URL_PREFIX) + +routes.static(config.URL_PREFIX + 'favicon/', 'favicon') +routes.static(config.URL_PREFIX, 'ui/dist/metube') app.add_routes(routes) diff --git a/favicon/browserconfig.xml b/favicon/browserconfig.xml index 70cb989..ed5dd79 100644 --- a/favicon/browserconfig.xml +++ b/favicon/browserconfig.xml @@ -2,7 +2,7 @@ - + #da532c diff --git a/favicon/site.webmanifest b/favicon/site.webmanifest index 4bae9f9..a476f60 100644 --- a/favicon/site.webmanifest +++ b/favicon/site.webmanifest @@ -3,12 +3,12 @@ "short_name": "", "icons": [ { - "src": "/favicon/android-chrome-192x192.png", + "src": "android-chrome-192x192.png", "sizes": "192x192", "type": "image/png" }, { - "src": "/favicon/android-chrome-384x384.png", + "src": "android-chrome-384x384.png", "sizes": "384x384", "type": "image/png" } diff --git a/ui/src/index.html b/ui/src/index.html index d73ae93..d57a30b 100644 --- a/ui/src/index.html +++ b/ui/src/index.html @@ -3,16 +3,15 @@ MeTube - - - - - - - + + + + + + - + -- cgit