Restore working request-handler.sx — was gutted, breaking all renders
The sx-handle-request function (which routes URLs to page rendering)
was removed from request-handler.sx. Without it, the server's
http_render_page calls sx-handle-request which doesn't exist,
returning nil for every request → 500 errors.
Restored from the last known working version (394c86b).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,44 @@
|
|||||||
|
(define
|
||||||
|
sx-handle-request
|
||||||
|
(fn
|
||||||
|
(path headers env)
|
||||||
|
(let
|
||||||
|
((is-ajax (or (has-key? headers "sx-request") (has-key? headers "hx-request")))
|
||||||
|
(path-expr (sx-parse-url path))
|
||||||
|
(page-ast (sx-eval-page path-expr env)))
|
||||||
|
(if
|
||||||
|
(nil? page-ast)
|
||||||
|
nil
|
||||||
|
(let
|
||||||
|
((nav-path (if (starts-with? path "/sx/") path (str "/sx" path))))
|
||||||
|
(if
|
||||||
|
is-ajax
|
||||||
|
(sx-render-ajax page-ast nav-path env)
|
||||||
|
(sx-render-full-page page-ast nav-path env)))))))
|
||||||
|
|
||||||
|
(define
|
||||||
|
sx-parse-url
|
||||||
|
(fn
|
||||||
|
(path)
|
||||||
|
(let
|
||||||
|
((p (cond (or (= path "/") (= path "/sx/") (= path "/sx")) "home" (starts-with? path "/sx/") (substring path 4 (string-length path)) (starts-with? path "/") (substring path 1 (string-length path)) :else path)))
|
||||||
|
(let ((spaced (join " " (split p ".")))) spaced))))
|
||||||
|
|
||||||
|
(define
|
||||||
|
sx-eval-page
|
||||||
|
(fn
|
||||||
|
(path-expr env)
|
||||||
|
(let
|
||||||
|
((exprs (sx-parse path-expr)))
|
||||||
|
(when
|
||||||
|
(not (empty? exprs))
|
||||||
|
(let
|
||||||
|
((expr (if (= (len exprs) 1) (first exprs) exprs))
|
||||||
|
(quoted (sx-auto-quote expr env)))
|
||||||
|
(let
|
||||||
|
((callable (if (symbol? quoted) (list quoted) quoted)))
|
||||||
|
(cek-try (fn () (eval-expr callable env)) (fn (err) nil))))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
sx-auto-quote
|
sx-auto-quote
|
||||||
(fn
|
(fn
|
||||||
@@ -10,66 +51,53 @@
|
|||||||
:else expr)))
|
:else expr)))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
sx-expr-to-str
|
sx-render-ajax
|
||||||
(fn
|
(fn
|
||||||
(expr)
|
(page-ast nav-path env)
|
||||||
(cond
|
(let
|
||||||
(string? expr)
|
((wrapped (list (make-symbol "~layouts/doc") :path nav-path page-ast))
|
||||||
(str "\"" expr "\"")
|
(aser-result (aser (list (make-symbol "quote") wrapped) env)))
|
||||||
(symbol? expr)
|
(let
|
||||||
(symbol-name expr)
|
((body-exprs (sx-parse aser-result)))
|
||||||
(list? expr)
|
(let
|
||||||
(str "(" (join " " (map sx-expr-to-str expr)) ")")
|
((body-expr (if (= (len body-exprs) 1) (first body-exprs) (cons (make-symbol "<>") body-exprs))))
|
||||||
:else (str expr))))
|
(render-to-html body-expr env))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
sx-handle-request
|
sx-render-full-page
|
||||||
(fn
|
(fn
|
||||||
(path headers env)
|
(page-ast nav-path env)
|
||||||
(let
|
(let
|
||||||
((is-ajax (or (has-key? headers "sx-request") (has-key? headers "hx-request")))
|
((wrapped (list (make-symbol "~layouts/doc") :path nav-path page-ast))
|
||||||
(raw-sx
|
(full-ast
|
||||||
(if
|
(list (make-symbol "~shared:layout/app-body") :content wrapped)))
|
||||||
(or (= path "/sx/") (= path "/"))
|
(let
|
||||||
"(home)"
|
((aser-result (aser (list (make-symbol "quote") full-ast) env)))
|
||||||
(slice path 4 (len path))))
|
|
||||||
(page-sx-raw (replace raw-sx "." " "))
|
|
||||||
(page-exprs (sx-parse page-sx-raw))
|
|
||||||
(page-expr (if (empty? page-exprs) nil (first page-exprs)))
|
|
||||||
(page-sx
|
|
||||||
(if
|
|
||||||
(nil? page-expr)
|
|
||||||
page-sx-raw
|
|
||||||
(sx-expr-to-str (sx-auto-quote page-expr env))))
|
|
||||||
(layout-sx (str "(~layouts/doc :path \"" path "\" " page-sx ")")))
|
|
||||||
(if
|
|
||||||
is-ajax
|
|
||||||
(let
|
(let
|
||||||
((full-sx (render-to-sx (first (sx-parse layout-sx)) env)))
|
((body-exprs (sx-parse aser-result)))
|
||||||
full-sx)
|
(let
|
||||||
(let
|
((body-expr (if (= (len body-exprs) 1) (first body-exprs) (cons (make-symbol "<>") body-exprs))))
|
||||||
((body-html (render-to-html (first (sx-parse layout-sx)) env)))
|
(let
|
||||||
(render-to-html
|
((body-html (render-to-html body-expr env))
|
||||||
(quasiquote
|
(page-source (serialize full-ast)))
|
||||||
(~shared:shell/sx-page-shell
|
(~shared:shell/sx-page-shell
|
||||||
:title "sx"
|
:title "SX"
|
||||||
:csrf ""
|
:csrf ""
|
||||||
:page-sx (unquote layout-sx)
|
:page-sx page-source
|
||||||
:body-html (unquote body-html)
|
:body-html body-html
|
||||||
:component-defs (unquote (env-get env "__shell-component-defs"))
|
:component-defs __shell-component-defs
|
||||||
:component-hash (unquote (env-get env "__shell-component-hash"))
|
:component-hash __shell-component-hash
|
||||||
:pages-sx (unquote (env-get env "__shell-pages-sx"))
|
:pages-sx __shell-pages-sx
|
||||||
:sx-css (unquote (env-get env "__shell-sx-css"))
|
:sx-css __shell-sx-css
|
||||||
:sx-css-classes (unquote (env-get env "__shell-sx-css-classes"))
|
:sx-css-classes __shell-sx-css-classes
|
||||||
:asset-url (unquote (env-get env "__shell-asset-url"))
|
:asset-url __shell-asset-url
|
||||||
:sx-js-hash (unquote (env-get env "__shell-sx-js-hash"))
|
:sx-js-hash __shell-sx-js-hash
|
||||||
:body-js-hash (unquote (env-get env "__shell-body-js-hash"))
|
:body-js-hash __shell-body-js-hash
|
||||||
:wasm-hash (unquote (env-get env "__shell-wasm-hash"))
|
:wasm-hash __shell-wasm-hash
|
||||||
:head-scripts nil
|
:head-scripts __shell-head-scripts
|
||||||
:body-scripts nil
|
:body-scripts __shell-body-scripts
|
||||||
:inline-css nil
|
:inline-css __shell-inline-css
|
||||||
:inline-head-js nil
|
:inline-head-js __shell-inline-head-js
|
||||||
:init-sx nil
|
:init-sx __shell-init-sx
|
||||||
:use-wasm true
|
:use-wasm (= (or (env-get env "SX_USE_WASM") "") "1")
|
||||||
:meta-html ""))
|
:meta-html ""))))))))
|
||||||
env))))))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user