2

我已经定义了一个简单的系统helloworld.asd

(asdf:defsystem #:helloworld
  :description "helloworld"
  :author "Duncan Bayne <duncan@bayne.id.au>"
  :license "WTFNMF"
  :depends-on (#:hunchentoot)
  :serial t
  :components ((:file "package")
               (:file "helloworld")))

... 中的包定义package.lisp

(defpackage #:helloworld
  (:use #:cl #:hunchentoot))

...以及相应的 hello world 网络服务器helloworld.lisp

(in-package #:helloworld)

(defvar *acceptor* (make-instance 'acceptor :port 4242))

(start *acceptor*)

(define-easy-handler (greet :uri "/hello") ()
  "<html><body><h1>Hello World!</h1></body></html>")

在 SLIME REPL 中,我使用以下命令启动 Web 服务器:

CL-USER> (load "/usr/home/duncan/code/helloworld/helloworld.asd")
CL-USER> (ql:quickload "helloworld")

如果我导航到http://localhost:4242/hello,我希望看到我的 hello world HTML。相反,我收到 404 错误,日志显示:

127.0.0.1 - [2017-08-10 08:18:19] "GET /hello HTTP/1.1" 404 341 "-" "Mozilla/5.0 (X11; FreeBSD amd64; rv:54.0) Gecko/20100101 Firefox/54.0"

我怀疑我在这里遗漏了一些相当明显的东西。任何提示/指向文档将不胜感激。系统详情如下:

Clozure Common Lisp Version 1.11 (FreebsdX8664)
FreeBSD 11.1-RELEASE amd64
Hunchentoot 1.2.37
Mozilla Firefox 54.0.1
SLIME 20170804.1113
4

1 回答 1

3

您正在创建一个实例ACCEPTOR而不是EASY-ACCEPTOR(或子类)。简易处理程序已注册,但您的接受者不会使用它。这应该有效,例如:

(defvar *acceptor* (make-instance 'easy-acceptor :port 4242))
(start *acceptor*)
(define-easy-handler (test :uri "/test") () "Pass")
于 2017-08-10T04:33:54.237 回答