feat: add redirect
This commit is contained in:
parent
e38ffbedf4
commit
c923126eff
3 changed files with 53 additions and 2 deletions
|
|
@ -16,4 +16,15 @@ in
|
|||
proxyWebsockets = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
type = "redirect";
|
||||
domain = "wekan.${net.devices.remote_proxy.domain}";
|
||||
endpoint = "/";
|
||||
force_ssl = true;
|
||||
port = 443;
|
||||
content = {
|
||||
target = "https://vikunja.${net.devices.remote_proxy.domain}/";
|
||||
status = 301;
|
||||
};
|
||||
}
|
||||
]
|
||||
|
|
@ -205,6 +205,25 @@ let
|
|||
proxyWebsockets = route.content.proxyWebsockets;
|
||||
};
|
||||
}
|
||||
else if route.type == "redirect" then
|
||||
let
|
||||
redirectTarget =
|
||||
if builtins.isString route.content then
|
||||
route.content
|
||||
else
|
||||
route.content.target;
|
||||
redirectStatus =
|
||||
if builtins.isAttrs route.content && route.content ? status then
|
||||
route.content.status
|
||||
else
|
||||
301;
|
||||
in
|
||||
{
|
||||
name = "= ${route.endpoint}";
|
||||
value = {
|
||||
return = "${toString redirectStatus} ${redirectTarget}";
|
||||
};
|
||||
}
|
||||
else if route.type == "inline" then
|
||||
let
|
||||
inlineBody =
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ let
|
|||
allowedWebContentKeys = [ "type" "files" ];
|
||||
allowedWebFileKeys = [ "path" "filePath" "contentType" "status" ];
|
||||
allowedInlineContentKeys = [ "body" "contentType" "status" ];
|
||||
allowedRedirectContentKeys = [ "target" "status" ];
|
||||
|
||||
ensureNoUnknownKeys = context: obj: allowedKeys:
|
||||
let
|
||||
|
|
@ -38,10 +39,10 @@ let
|
|||
else
|
||||
throw "Endpoint at index ${toString index} must define type as a string.";
|
||||
_type =
|
||||
if lib.elem typeValue [ "proxy" "web" "inline" ] then
|
||||
if lib.elem typeValue [ "proxy" "web" "inline" "redirect" ] then
|
||||
null
|
||||
else
|
||||
throw "Endpoint at index ${toString index} type must be 'proxy', 'web', or 'inline'.";
|
||||
throw "Endpoint at index ${toString index} type must be 'proxy', 'web', 'inline', or 'redirect'.";
|
||||
_domain =
|
||||
if endpoint ? domain && builtins.isString endpoint.domain && endpoint.domain != "" then
|
||||
null
|
||||
|
|
@ -131,6 +132,26 @@ let
|
|||
) filesValue;
|
||||
in
|
||||
null
|
||||
else if typeValue == "redirect" then
|
||||
if builtins.isString contentValue then
|
||||
null
|
||||
else if builtins.isAttrs contentValue then
|
||||
let
|
||||
____ = ensureNoUnknownKeys "Redirect content at endpoint index ${toString index}" contentValue allowedRedirectContentKeys;
|
||||
_____ =
|
||||
if contentValue ? target && builtins.isString contentValue.target && contentValue.target != "" then
|
||||
null
|
||||
else
|
||||
throw "Redirect endpoint at index ${toString index} must define content.target as a non-empty string when content is an attrset.";
|
||||
______ =
|
||||
if !(contentValue ? status) || builtins.isInt contentValue.status then
|
||||
null
|
||||
else
|
||||
throw "Redirect endpoint at index ${toString index} content.status must be an int when provided.";
|
||||
in
|
||||
null
|
||||
else
|
||||
throw "Redirect endpoint at index ${toString index} must define content as a string or an attrset."
|
||||
else
|
||||
if builtins.isString contentValue then
|
||||
null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue