diff --git a/config/endpoints/vikunja.nix b/config/endpoints/vikunja.nix index 0212f71..ec801ba 100644 --- a/config/endpoints/vikunja.nix +++ b/config/endpoints/vikunja.nix @@ -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; + }; + } ] \ No newline at end of file diff --git a/intermediate/nginx.nix b/intermediate/nginx.nix index e44f4da..3b17093 100644 --- a/intermediate/nginx.nix +++ b/intermediate/nginx.nix @@ -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 = diff --git a/validation/endpoints.nix b/validation/endpoints.nix index cf60b0f..50c7c7d 100644 --- a/validation/endpoints.nix +++ b/validation/endpoints.nix @@ -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