aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <alexta69@gmail.com>2019-12-03 23:18:14 +0200
committerAlex <alexta69@gmail.com>2019-12-03 23:18:14 +0200
commita524f1faf38c128eb8dabdfeef1fbcdc23ae223d (patch)
treeaadef959c5a7483583256625fd35140505e06679
parentadd "completed" panel (diff)
downloadmetube-a524f1faf38c128eb8dabdfeef1fbcdc23ae223d.tar.gz
metube-a524f1faf38c128eb8dabdfeef1fbcdc23ae223d.tar.bz2
metube-a524f1faf38c128eb8dabdfeef1fbcdc23ae223d.zip
add configurable URL prefix
-rw-r--r--README.md7
-rw-r--r--app/main.py23
-rw-r--r--favicon/browserconfig.xml2
-rw-r--r--favicon/site.webmanifest4
-rw-r--r--ui/src/index.html15
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 @@
<browserconfig>
<msapplication>
<tile>
- <square150x150logo src="/favicon/mstile-150x150.png"/>
+ <square150x150logo src="favicon/mstile-150x150.png"/>
<TileColor>#da532c</TileColor>
</tile>
</msapplication>
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 @@
<head>
<meta charset="utf-8">
<title>MeTube</title>
- <base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
- <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
- <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
- <link rel="manifest" href="/favicon/site.webmanifest">
- <link rel="mask-icon" href="/favicon/safari-pinned-tab.svg" color="#5bbad5">
- <link rel="shortcut icon" href="/favicon/favicon.ico">
+ <link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-touch-icon.png">
+ <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
+ <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
+ <link rel="manifest" href="favicon/site.webmanifest">
+ <link rel="mask-icon" href="favicon/safari-pinned-tab.svg" color="#5bbad5">
+ <link rel="shortcut icon" href="favicon/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
- <meta name="msapplication-config" content="/favicon/browserconfig.xml">
+ <meta name="msapplication-config" content="favicon/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
</head>
<body>
bgstack15