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?

deadghost
  • 5,017
  • 3
  • 34
  • 46

3 Answers3

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.

JEPrice
  • 627
  • 7
  • 10
2

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*)))
Svante
  • 50,694
  • 11
  • 78
  • 122
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/)

Svante
  • 50,694
  • 11
  • 78
  • 122
JEPrice
  • 627
  • 7
  • 10