球拍 URL 调度
我正在尝试将 URL 调度与 Racket(以前称为 PLT 方案)连接起来。我已经查看了教程和服务器文档。我不知道如何将请求路由到相同的 servlet。
具体示例:
#lang scheme (require web-server/servlet) (require web-server/dispatch) (provide/contract (start (request? . -> . response/c))) (define (start request) (blog-dispatch request)) (define-values (blog-dispatch blog-url) (dispatch-rules (("") list-posts) (("posts" (string-arg)) review-post) (("archive" (integer-arg) (integer-arg)) review-archive) (else list-posts))) (define (list-posts req) `(list-posts)) (define (review-post req p) `(review-post ,p)) (define (review-archive req y m) `(review-archive ,y ,m)) (require web-server/servlet-env) (serve/servlet start #:launch-browser? #t #:quit? #f #:listen-ip #f #:port 8080 #:extra-files-paths (list (build-path "js") (build-path "css")) #:servlet-path "")
假设上面的代码,localhost:8080/
转到一个显示“list-posts”的页面。转到 localhost:8080/posts/test 会转到 Racket“未找到文件”页面(我希望它会转到显示“review-post test”的页面)。
感觉就像我错过了一些小而明显的东西。谁能给我提示吗?
I'm trying to hook up URL dispatch with Racket (formerly PLT Scheme). I've taken a look at the tutorial and the server documentation. I can't figure out how to route requests to the same servlets.
Specific example:
#lang scheme (require web-server/servlet) (require web-server/dispatch) (provide/contract (start (request? . -> . response/c))) (define (start request) (blog-dispatch request)) (define-values (blog-dispatch blog-url) (dispatch-rules (("") list-posts) (("posts" (string-arg)) review-post) (("archive" (integer-arg) (integer-arg)) review-archive) (else list-posts))) (define (list-posts req) `(list-posts)) (define (review-post req p) `(review-post ,p)) (define (review-archive req y m) `(review-archive ,y ,m)) (require web-server/servlet-env) (serve/servlet start #:launch-browser? #t #:quit? #f #:listen-ip #f #:port 8080 #:extra-files-paths (list (build-path "js") (build-path "css")) #:servlet-path "")
Assuming the above code, localhost:8080/
goes to a page that says "list-posts". Going to localhost:8080/posts/test
goes to a Racket "file not found" page (I'd expect it to go to a page that says "review-post test").
It feels like I'm missing something small and obvious. Can anyone give me a hint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你写的不是一个完整的程序,所以我无法调试它。
这是一个带有注释的程序,可能可以实现您想要的功能:
因为函数
list-posts
、review-post
和review-archive
不返回 HTML 的合理 xexpr 编码,您必须查看源代码才能正确看到它们。请随时直接给我发电子邮件或向 PLT 方案邮件列表发送电子邮件。 (注意:我们将 PLT 方案重命名为“Racket”,以便您在发帖时可以看到它。)
Jay McCarthy
What you've written is not a whole program, so I cannot debug it.
Here is a program with annotations that does what you want, probably:
Because the functions
list-posts
,review-post
, andreview-archive
don't return sensible xexpr encodings of HTML, you'll have to view source to see them right.Please feel free to email me directly or email the PLT Scheme mailing list. (Note: We are renaming PLT Scheme to "Racket" so you may see that when you post.)
Jay McCarthy