How do I start Hunchentoot?
Asked Answered
B

3

7

How do I start Hunchentoot on a project? I looked over Edi Weitz's guide and everything went smoothly until after installation. The listed tutorials were either broken or skimmed over actual server usage.

I have my asdf file, installed dependencies with quicklisp, and set up a dispatch table. How do I get Hunchentoot to work with this stuff?

Belsen answered 2/11, 2013 at 6:24 Comment(1)
weitz.de/hunchentoot/#start like so?Aracelyaraceous
C
3

You invoke start on an instance of an acceptor.

If you use the basic easy-handler mechanism that comes with hunchentoot, that would be an easy-acceptor.

You will want to have a mechanism in place to start and stop your server. That might look like this:

(defvar *acceptor* nil)

(defun start-server ()
  (stop-server)
  (start (setf *acceptor*
               (make-instance 'easy-acceptor
                              :port 4242))))

(defun stop-server ()
  (when *acceptor*
    (stop *acceptor*)))
Carrolcarroll answered 2/11, 2013 at 16:50 Comment(0)
E
3

To update, I've improved upon Svante's answer:

(defun start-server ()
  (stop-server)
  (start (setf *acceptor*
               (make-instance 'easy-acceptor
                              :port 4242))))

(defun stop-server ()
  (when *acceptor*
    (when started-p *acceptor*
     (stop *acceptor*))))

Prior to starting the server, acceptor is nil. After the server has been started (even if it has subsequently been stopped) it is no longer nil. The started-p test checks to see if an initialized easy-acceptor is started. If you try to stop an already stopped acceptor, you receive an error.

Expectant answered 23/10, 2017 at 22:31 Comment(0)
E
0
(start (defparameter hunchentoot-listener
         (make-instance 'easy-acceptor
                        :port 4242
                        :document-root #p"/path/to/your/html/")))

will get you a running web server on port 4242 (http://localhost:4242/)

Expectant answered 11/9, 2017 at 0:49 Comment(3)
Don't use defparameter like that. You want your toplevel forms to be reloadable.Carrolcarroll
I'm still on the up slope of the learning curve - can you give an example of a more acceptable way?Expectant
I added an example to my answer.Carrolcarroll

© 2022 - 2024 — McMap. All rights reserved.