Created
November 25, 2025 15:32
-
-
Save cablehead/985945bfd0bbda525a0ee7e72dac6bbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use /root/.config/nushell/scripts/xs.nu * | |
| def decode-basic-auth [header?: string] { | |
| if ($header | is-empty) or (not ($header | str starts-with 'Basic ')) { | |
| return null | |
| } | |
| let encoded_part = $header | str replace 'Basic ' '' | |
| # handle base64 decode errors | |
| let decoded = try { | |
| $encoded_part | decode base64 | decode utf-8 | str trim | |
| } catch { | |
| return null | |
| } | |
| # handle missing colon separator | |
| if not ($decoded | str contains ':') { | |
| return {username: $decoded password: ""} | |
| } | |
| # split only on first colon to preserve password with colons | |
| let colon_pos = $decoded | str index-of ':' | |
| let username = $decoded | str substring 0..<($colon_pos) | |
| let password = $decoded | str substring ($colon_pos + 1).. | |
| {username: $username password: $password} | |
| } | |
| sleep 1sec | |
| $env.XS_ADDR = "/session/store" | |
| $env.smidgeons_id = xs-context "smidgeons" | |
| {|req| | |
| let body = $in | |
| if ($req.headers.host | str ends-with ".cross.stream") { | |
| let attempt = decode-basic-auth $req.headers?.authorization? | |
| if ($attempt | is-not-empty) { | |
| if ("tokens" | path join $attempt.username | path exists) { | |
| return ($body | .reverse-proxy "http://localhost:3021") | |
| } | |
| } | |
| return (.static "www" $req.path) | |
| } | |
| if $req.method != "GET" { | |
| return (.response {status: 404}; "sorry, eh") | |
| } | |
| if $req.path == "/api" or ($req.path | str starts-with "/api/") { | |
| return ( | |
| .reverse-proxy "http://localhost:3021" { | |
| strip_prefix: "/api" | |
| query: ($req.query | upsert "context-id" $env.smidgeons_id) | |
| } | |
| ) | |
| } | |
| .static "/common/stream-of-snippets/dist" $req.path --fallback "index.html" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment