d0u9 / youtube-dl-webui

Another webui for youtube-dl powered by Flask.
GNU General Public License v2.0
329 stars 111 forks source link

baseurl option for working with reverse proxies #36

Open hariseldon99 opened 4 years ago

hariseldon99 commented 4 years ago

Any thoughts on adding an option to change the baseurl? I ask because it'd be cool if this could work with reverse proxies like nginx

thomsh commented 3 years ago

:+1: I've been annoyed by this as well, I made a quick dirty patch to the code to support my static prefix.

Spoiler: Super dirty yolo code edit: Nginx config: ``` location /iamapig/ { # [...] proxy_pass http://10.1.2.3:5000; } ``` Ugly code diff: python + js ```diff diff --git a/youtube_dl_webui/server.py b/youtube_dl_webui/server.py index 62d0b3d..08a89af 100644 --- a/youtube_dl_webui/server.py +++ b/youtube_dl_webui/server.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json @@ -8,19 +8,20 @@ from flask import render_template from flask import request from multiprocessing import Process from copy import deepcopy MSG = None - -app = Flask(__name__) +URL_PREFIX="iamapig" +app = Flask(__name__, static_url_path="{}/static".format(URL_PREFIX)) MSG_INVALID_REQUEST = {'status': 'error', 'errmsg': 'invalid request'} -@app.route('/') +@app.route(URL_PREFIX + '/') def index(): return render_template('index.html') -@app.route('/task', methods=['POST']) +@app.route(URL_PREFIX + '/task', methods=['POST']) def add_task(): payload = request.get_json() @@ -28,7 +29,7 @@ def add_task(): return json.dumps(MSG.get()) -@app.route('/task/list', methods=['GET']) +@app.route(URL_PREFIX + '/task/list', methods=['GET']) def list_task(): payload = {} exerpt = request.args.get('exerpt', None) @@ -43,20 +44,20 @@ def list_task(): return json.dumps(MSG.get()) -@app.route('/task/state_counter', methods=['GET']) +@app.route(URL_PREFIX + '/task/state_counter', methods=['GET']) def list_state(): MSG.put('state', None) return json.dumps(MSG.get()) -@app.route('/task/batch/', methods=['POST']) +@app.route(URL_PREFIX + '/task/batch/', methods=['POST']) def task_batch(action): payload={'act': action, 'detail': request.get_json()} MSG.put('batch', payload) return json.dumps(MSG.get()) -@app.route('/task/tid/', methods=['DELETE']) +@app.route(URL_PREFIX + '/task/tid/', methods=['DELETE']) def delete_task(tid): del_flag = request.args.get('del_file', False) payload = {} @@ -67,7 +68,7 @@ def delete_task(tid): return json.dumps(MSG.get()) -@app.route('/task/tid/', methods=['PUT']) +@app.route(URL_PREFIX + '/task/tid/', methods=['PUT']) def manipulate_task(tid): payload = {} payload['tid'] = tid @@ -84,7 +85,7 @@ def manipulate_task(tid): return json.dumps(MSG.get()) -@app.route('/task/tid//status', methods=['GET']) +@app.route(URL_PREFIX + '/task/tid//status', methods=['GET']) def query_task(tid): payload = {} payload['tid'] = tid @@ -99,7 +100,7 @@ def query_task(tid): return json.dumps(MSG.get()) -@app.route('/config', methods=['GET', 'POST']) +@app.route(URL_PREFIX + '/config', methods=['GET', 'POST']) def get_config(): payload = {} if request.method == 'POST': @@ -115,7 +116,7 @@ def get_config(): ### # test cases ### -@app.route('/test/') +@app.route(URL_PREFIX + '/test/') def test(case): return render_template('test/{}.html'.format(case)) @@ -134,4 +135,3 @@ class Server(Process): MSG = self.msg_cli app.run(host=self.host, port=int(self.port), use_reloader=False) - diff --git a/youtube_dl_webui/static/js/global.js b/youtube_dl_webui/static/js/global.js index 7d5935b..4f6e329 100644 --- a/youtube_dl_webui/static/js/global.js +++ b/youtube_dl_webui/static/js/global.js @@ -3,7 +3,7 @@ var videoDownload = (function (Vue, extendAM){ var VueToast = window.vueToasts ? window.vueToasts.default || window.vueToasts : window.vueToasts; videoDownload.vm = null; videoDownload.tasksData = { - headPath: 'http://localhost:5000/', + headPath: '/iamapig/', videoList: [], videoListCopy: [], showModal: false, @@ -293,7 +293,7 @@ var videoDownload = (function (Vue, extendAM){ videoDownload.init = function(){ var that = this; - that.tasksData.headPath = window.location.protocol + '//' + window.location.host + '/'; + that.tasksData.headPath = window.location.protocol + '//' + window.location.host + '/iamapig/'; that.createVm(); that.getTaskList(); } ```
floviolleau commented 3 years ago

Hi,

I'm in the same situation.

Can you please make a PR of your changes?

Thanks