2017-08-09 134 views
2

我在helloworld.asd定義的簡單系統:端點返回404

(asdf:defsystem #:helloworld 
    :description "helloworld" 
    :author "Duncan Bayne <[email protected]>" 
    :license "WTFNMF" 
    :depends-on (#:hunchentoot) 
    :serial t 
    :components ((:file "package") 
       (:file "helloworld"))) 

...在package.lisp包定義:

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

...和相應的hello world webserver 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 I與啓動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 

回答

3

要製作ACCEPTOR而不是EASY-ACCEPTOR實例(或子類)。簡單的處理程序已註冊,但您的接受者不會使用它。這應該工作,例如:

(defvar *acceptor* (make-instance 'easy-acceptor :port 4242)) 
(start *acceptor*) 
(define-easy-handler (test :uri "/test")() "Pass") 
+0

謝謝:)我沒有注意到,有'ACCEPTOR'多個類。 –

+0

@DuncanBayne它發生:-) – coredump