mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2026-01-31 16:36:29 +00:00
feat: do all the backend balancing on the invidious side
This will make invidious easier to maintain and escalate without the need of an overcomplicated reverse proxy configuration and multiple invidious instances with each one with a different configuration (in this case, invidious companion)
This commit is contained in:
16
src/invidious/routes/backend_switcher.cr
Normal file
16
src/invidious/routes/backend_switcher.cr
Normal file
@@ -0,0 +1,16 @@
|
||||
{% skip_file if flag?(:api_only) %}
|
||||
|
||||
module Invidious::Routes::BackendSwitcher
|
||||
def self.switch(env)
|
||||
referer = get_referer(env)
|
||||
backend_id = env.params.query["backend_id"]?.try &.to_i
|
||||
|
||||
if backend_id.nil?
|
||||
return error_template(400, "Backend ID is required")
|
||||
end
|
||||
|
||||
env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(env.request.headers["Host"], backend_id)
|
||||
|
||||
env.redirect referer
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user