openresty-config/lua/502-invidious.lua
2025-02-11 20:13:49 -03:00

72 lines
1.5 KiB
Lua

ngx.header.content_type = 'text/html';
local backend_num = ngx.shared.servers:get("inv-backends");
-- local backend_num = 4;
local function generate_backend_list()
local html = ""
for i=1, backend_num do
html = html .. "<p><a href='/switchbackend?backend_id=" .. i .. "'>Backend " .. i .. "</a></p>"
end
return html
end
ngx.say([[
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="2">
<style>
html {
background-color: #111111;
color: #FFFFFF;
font-family: sans-serif;
}
a:link {
color: rgb(255, 180, 255);
}
a:visited {
color: rgb(255, 180, 255);
}
.content {
padding: 20px 20px;
margin: 0 auto;
max-width: 780px;
width: 70%;
min-height: 60vh;
word-wrap: break-word;
line-height: 1.5em;
}
h1 {
color: red;
}
</style>
<title>502 Bad Gateway</title>
</head>
<body>
<div class="content">
<h1>502 Bad Gateway</h1>
<p>Looks like you got a dead backend...</p>
<p>If you don't get an alive backend after 1 minute, it's because something is wrong...</p>
<p><b>Refreshing automatically in 2 seconds</b></p>
<p>Do you want to switch to another backend?</p>
]] .. generate_backend_list() .. [[
<div style="max-width: 60%;">
<p>
<i>If this page doesn't redirect you to any alive backend
then there is no available backends alive.
</i>
</p>
</div>
</div>
</body>
</html>
]])