feat: add redirect

This commit is contained in:
Katharina Heidenreich 2026-04-04 17:22:37 +02:00
parent e38ffbedf4
commit c923126eff
3 changed files with 53 additions and 2 deletions

View file

@ -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