eudoxia0 / lucerne

A web framework for Common Lisp, built on Clack
http://borretti.me/lucerne/
142 stars 19 forks source link

Clack added :server keyword, causing a code break on sites like Heroku #27

Closed file13 closed 5 years ago

file13 commented 5 years ago

Hello,

Clack recently added the ability to specify a server address on start up. In the process, they changed the default address from "0.0.0.0" to "127.0.0.1" on Hunchentoot. This shouldn't matter in most cases, but for sites like Heroku, it caused the app to never properly bind to the port, cause as startup timeout.

A simple change in start in the keyword args should resolve this (and add this feature). I'll try to create a pull request when I have more time.

In the meantime, I was able to use this as a work around:

(defmethod lucerne.ctl:start ((app lucerne.app:base-app) &key (port 8000) (server :hunchentoot) (address "0.0.0.0") debug silent)
  "Bring up @cl:param(app), by default on @cl:param(port) 8000. If the server
was not running, it returns @c(T). If the server was running, it restarts it and
returns @c(NIL)."
  (let ((rebooted nil))
    (when (lucerne.app:handler app)
      ;; The handler already exists, meaning the server is running. Bring it
      ;; down before bringing it up again.
      (setf rebooted t)
      (clack:stop (lucerne.app:handler app)))
    (setf (lucerne.app:handler app)
          (clack:clackup
           (lack:builder (let ((clack-app (lucerne.app:build-app app)))
                           (if debug
                               (funcall clack-errors:*clack-error-middleware*
                                        clack-app
                                        :debug t)
                               clack-app)))
           :port port
           :server server
           :address address
           :use-default-middlewares nil
           :silent silent))
    (sleep 1)
    ;; If it was rebooted, return nil. Otherwise t.
    (not rebooted)))

This might come in handy for other folks in the meantime.

Thanks!