I'm sure I'm overlooking something simple in the documentation, but I've Googled madly and not found the answer. How do I specify my own 404 page in Hunchentoot?
Thanks,
Patrick
On Thu, May 31, 2012 at 8:12 PM, Patrick May patrick.may@mac.com wrote:
I'm sure I'm overlooking something simple in the documentation, but
I've Googled madly and not found the answer. How do I specify my own 404 page in Hunchentoot?
This is actually documented, albeit maybe a bit hard to find: http://weitz.de/hunchentoot/#acceptor-status-message - I'd gladly accept a documentation patch that puts some prose describing how to customize error pages into a separate chapter.
With no further customization, the error page templates are located in the www/errors/ subdirectory of the Hunchentoot source distribution.
Let me know if you have further questions.
-Hans
Thanks to you and Ala'a for the quick answers.
Regards,
Patrick
On May 31, 2012, at 12:24 PM, Hans Hübner wrote:
On Thu, May 31, 2012 at 8:12 PM, Patrick May patrick.may@mac.com wrote: I'm sure I'm overlooking something simple in the documentation, but I've Googled madly and not found the answer. How do I specify my own 404 page in Hunchentoot?
This is actually documented, albeit maybe a bit hard to find: http://weitz.de/hunchentoot/#acceptor-status-message - I'd gladly accept a documentation patch that puts some prose describing how to customize error pages into a separate chapter.
With no further customization, the error page templates are located in the www/errors/ subdirectory of the Hunchentoot source distribution.
Let me know if you have further questions.
-Hans
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Dredging up an old question….
On this machine I don’t have the code I used the last time I asked this question. I tried this:
(defmethod acceptor-status-message ((acceptor (eql *test-acceptor*)) (http-status-code (eql 404))) (display-404-page))
but it doesn’t display my own 404 page. What Hunchentoot concept am I missing?
Thanks,
Patrick
On May 31, 2012, at 3:24 PM, Hans Hübner hans.huebner@gmail.com wrote:
On Thu, May 31, 2012 at 8:12 PM, Patrick May patrick.may@mac.com wrote: I'm sure I'm overlooking something simple in the documentation, but I've Googled madly and not found the answer. How do I specify my own 404 page in Hunchentoot?
This is actually documented, albeit maybe a bit hard to find: http://weitz.de/hunchentoot/#acceptor-status-message - I'd gladly accept a documentation patch that puts some prose describing how to customize error pages into a separate chapter.
With no further customization, the error page templates are located in the www/errors/ subdirectory of the Hunchentoot source distribution.
Let me know if you have further questions.
-Hans
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Patrick,
you cannot specialize a generic function on the run-time value of a variable. In your method definition, you are trying to specialize the ACCEPTOR argument on (EQL *TEST-ACCEPTOR*)), but *TEST-ACCEPTOR* in that definition will be evaluated at compile-time, not at run-time. Thus, you're probably specializing on NIL or some other random object. Is there any reason why you want to specialize on a particular instance rather than the class of the acceptor (or T)?
-Hans
2014-05-07 23:15 GMT+02:00 Patrick May patrick.may@mac.com:
Dredging up an old question....
On this machine I don't have the code I used the last time I asked this question. I tried this:
(defmethod acceptor-status-message ((acceptor (eql *test-acceptor*)) (http-status-code (eql 404))) (display-404-page))
but it doesn't display my own 404 page. What Hunchentoot concept am I missing?
Thanks,
Patrick
On May 31, 2012, at 3:24 PM, Hans Hübner hans.huebner@gmail.com wrote:
On Thu, May 31, 2012 at 8:12 PM, Patrick May patrick.may@mac.com wrote: I'm sure I'm overlooking something simple in the documentation, but I've Googled madly and not found the answer. How do I specify my own 404 page in Hunchentoot?
This is actually documented, albeit maybe a bit hard to find: http://weitz.de/hunchentoot/#acceptor-status-message - I'd gladly accept a documentation patch that puts some prose describing how to customize error pages into a separate chapter.
With no further customization, the error page templates are located in the www/errors/ subdirectory of the Hunchentoot source distribution.
Let me know if you have further questions.
-Hans
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Tbnl-devel mailing list Tbnl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/tbnl-devel
Hans,
That would be “debugging by public embarrassment” in action. ;-)
Removing the incorrect eql specialization still doesn’t result in my 404 page being displayed. Do I have to subclass acceptor to get it to work?
Thanks,
Patrick
On May 8, 2014, at 2:28 AM, Hans Hübner hans.huebner@gmail.com wrote:
Patrick,
you cannot specialize a generic function on the run-time value of a variable. In your method definition, you are trying to specialize the ACCEPTOR argument on (EQL *TEST-ACCEPTOR*)), but *TEST-ACCEPTOR* in that definition will be evaluated at compile-time, not at run-time. Thus, you're probably specializing on NIL or some other random object. Is there any reason why you want to specialize on a particular instance rather than the class of the acceptor (or T)?
-Hans
2014-05-07 23:15 GMT+02:00 Patrick May patrick.may@mac.com: Dredging up an old question….
On this machine I don’t have the code I used the last time I asked this question. I tried this:
(defmethod acceptor-status-message ((acceptor (eql *test-acceptor*)) (http-status-code (eql 404))) (display-404-page))
but it doesn’t display my own 404 page. What Hunchentoot concept am I missing?
Thanks,
Patrick
On May 31, 2012, at 3:24 PM, Hans Hübner hans.huebner@gmail.com wrote:
On Thu, May 31, 2012 at 8:12 PM, Patrick May patrick.may@mac.com wrote: I'm sure I'm overlooking something simple in the documentation, but I've Googled madly and not found the answer. How do I specify my own 404 page in Hunchentoot?
This is actually documented, albeit maybe a bit hard to find: http://weitz.de/hunchentoot/#acceptor-status-message - I'd gladly accept a documentation patch that puts some prose describing how to customize error pages into a separate chapter.
With no further customization, the error page templates are located in the www/errors/ subdirectory of the Hunchentoot source distribution.
Let me know if you have further questions.
-Hans
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Tbnl-devel mailing list Tbnl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/tbnl-devel
2014-05-08 15:07 GMT+02:00 Patrick May patrick.may@mac.com:
Removing the incorrect eql specialization still doesn't result in my 404 page being displayed. Do I have to subclass acceptor to get it to work?
No, it works just fine without an extra subclass, e.g.:
(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) "NOT FOUND")
-Hans
Hmm. Here’s a full working example:
(in-package :common-lisp-user)
(ql:quickload :hunchentoot) (ql:quickload :drakma) (ql:quickload :cl-who)
(defpackage :org.softwarematters.hunchentoot-test (:nicknames :hunchentoot-test :web-test) (:use :common-lisp :cl-who))
(in-package :web-test)
;;; Define the web server acceptor
(defparameter *test-acceptor* (make-instance 'hunchentoot:easy-acceptor :port 8081 :document-root #p"/Users/Patrick/src/lisp/web/" :access-log-destination "/tmp/web-test-access.log" :message-log-destination "/tmp/web-test-message.log"))
;;; A couple of macros for encapsulating the details of a standard page. ;;; This came from Stack Overflow (How to connect a web app to Hunchentoot) ;;; and http://www.adampetersen.se/articles/lispweb.htm.
(defmacro standard-page ((&key title) &body body) "Abstract away the placing of standard page stuff." `(with-html-output-to-string (*standard-output* nil :prologue t :indent t) (:html :xmlns "http://www.w3.org/1999/xhtml" :xml:lang "en" :lang "en" (:head (:meta :http-equiv "content-type" :content "text/html;charset=UTF-8") (:title ,title) (:link :type "text/css" :rel "stylesheet" :href "/test.css")) (:body (:div :id "header") ,@body (:div :id "footer")))))
(defmacro defpage (name (title) &body body) `(progn (defmethod ,name () (standard-page (,title) ,@body)) (push (create-prefix-dispatcher ,(format nil "/~(~a~).html" name) ',name) *dispatch-table*)))
;;; URI implementations
(defun display-home-page () "Display the home page." (hunchentoot:redirect "/index.html"))
(push (hunchentoot:create-regex-dispatcher "^/$" 'display-home-page) hunchentoot:*dispatch-table*)
(hunchentoot:define-easy-handler (home-page-handler :uri "/index.html" :default-request-type :GET) () "Return the home page." (standard-page (:title "Web Test Home Page") (:h1 "Web Test") (:p "remote IP address: " (format t "~A" (hunchentoot:remote-addr*))) (:p "real remote IP address: " (format t "~A" (hunchentoot:real-remote-addr))) (:p "headers: " (:br) (dolist (header (hunchentoot:headers-in*)) (format t "~A: ~A<br/>" (car header) (cdr header)))) (:p "GET parameters: " (format t "~A" (hunchentoot:get-parameters*)))))
;;; Override 404 handling
(defun display-404-page () (standard-page (:title "Web Test 404 Page") (:h1 "404")))
(defmethod acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
;(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) "NOT FOUND")
;;; Start the web server
(hunchentoot:start *test-acceptor*)
I tried calling (display-404-page) in an easy-handler and it works fine.
Thanks for any help.
Regards,
Patrick
On May 8, 2014, at 9:12 AM, Hans Hübner hans.huebner@gmail.com wrote:
2014-05-08 15:07 GMT+02:00 Patrick May patrick.may@mac.com: Removing the incorrect eql specialization still doesn’t result in my 404 page being displayed. Do I have to subclass acceptor to get it to work?
No, it works just fine without an extra subclass, e.g.:
(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) "NOT FOUND")
-Hans
Your example works for me if I change:
(defmethod acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
to:
(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
-Bill
Thanks! Silently adding a new generic method — one of my favorite tricks.
Regards,
Patrick
On May 8, 2014, at 10:41 AM, Bill St. Clair billstclair@gmail.com wrote:
Your example works for me if I change:
(defmethod acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
to:
(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
-Bill
I spoke too soon. I changed it to specify hunchentoot:acceptor-status-messsage, but no joy. Then I modified the package to use :hunchentoot and removed all the “hunchentoot:” package specifiers in the code, but still see the default 404 page in my browser.
I’m using Clozure CL (64-bit) on OS X.
Thanks,
Patrick
On May 8, 2014, at 12:23 PM, Patrick May patrick.may@mac.com wrote:
Thanks! Silently adding a new generic method — one of my favorite tricks.
Regards,
Patrick
On May 8, 2014, at 10:41 AM, Bill St. Clair billstclair@gmail.com wrote:
Your example works for me if I change:
(defmethod acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
to:
(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
-Bill
Tbnl-devel mailing list Tbnl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/tbnl-devel
Same here.
hunchentoot:*hunchentoot-version* is "1.2.26" (lisp-implementation-version) is "Version 1.9-r16025M (DarwinX8664)"
-Bill
On Thu, May 8, 2014 at 12:31 PM, Patrick May patrick.may@mac.com wrote:
I spoke too soon. I changed it to specify hunchentoot:acceptor-status-messsage, but no joy. Then I modified the package to use :hunchentoot and removed all the “hunchentoot:” package specifiers in the code, but still see the default 404 page in my browser.
I’m using Clozure CL (64-bit) on OS X.
Thanks,
Patrick
On May 8, 2014, at 12:23 PM, Patrick May patrick.may@mac.com wrote:
Thanks! Silently adding a new generic method — one of my favorite tricks.
Regards,
Patrick
On May 8, 2014, at 10:41 AM, Bill St. Clair billstclair@gmail.com wrote:
Your example works for me if I change:
(defmethod acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
to:
(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
-Bill
Tbnl-devel mailing list Tbnl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/tbnl-devel
Tbnl-devel mailing list Tbnl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/tbnl-devel
That was it. I updated to 1.2.26 from 1.2.21 and it worked. Thanks for the help!
Regards,
Patrick
On May 8, 2014, at 12:38 PM, Bill St. Clair billstclair@gmail.com wrote:
Same here.
hunchentoot:*hunchentoot-version* is "1.2.26" (lisp-implementation-version) is "Version 1.9-r16025M (DarwinX8664)"
-Bill
On Thu, May 8, 2014 at 12:31 PM, Patrick May patrick.may@mac.com wrote: I spoke too soon. I changed it to specify hunchentoot:acceptor-status-messsage, but no joy. Then I modified the package to use :hunchentoot and removed all the “hunchentoot:” package specifiers in the code, but still see the default 404 page in my browser.
I’m using Clozure CL (64-bit) on OS X.
Thanks,
Patrick
On May 8, 2014, at 12:23 PM, Patrick May patrick.may@mac.com wrote:
Thanks! Silently adding a new generic method — one of my favorite tricks.
Regards,
Patrick
On May 8, 2014, at 10:41 AM, Bill St. Clair billstclair@gmail.com wrote:
Your example works for me if I change:
(defmethod acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
to:
(defmethod hunchentoot:acceptor-status-message (acceptor (http-status-code (eql 404)) &key) (display-404-page))
-Bill
Tbnl-devel mailing list Tbnl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/tbnl-devel
Tbnl-devel mailing list Tbnl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/tbnl-devel
For dynamic 404 contents, This works for the stock easy-acceptor.
(defun 404-dispatcher (request) '404-page)
(defun 404-page () "404 is here!")
(push-end-new '404-dispatcher *dispatch-table*) ;; make sure the dispatcher is at the end of the *dispatch-table*
HIH
Ala'a
On Thu, May 31, 2012 at 10:12 PM, Patrick May patrick.may@mac.com wrote:
I'm sure I'm overlooking something simple in the documentation, but I've Googled madly and not found the answer. How do I specify my own 404 page in Hunchentoot?
Thanks,
Patrick
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel