routescommon-lisphunchentoot

Hunchentoot (easy-routes) routes showing up in separate project?


I have two separate asdf systems/defprojects. Both of them use hunchentoot and easy-routes.

I put my code at the end but here is a quick summary:

Project 1 Port - 8000 || Document root: .../sending-app/web/ || HTML Page: admin.html

Project 2 Port - 9000 || Document root - .../sales-web/web/ || HTML Page: admin.html

They have the same route names and paths (/admin) but different ports and different projects.

However, when i run start-server2 while in project two, the routes from project 1 is active. Any change made to /sending-app/web/admin.html is not reflected even though the port is 9000.

What do you think may be the issue?

Project 1:

(in-package :project-one)

;; ==== Server Setup ==== ;;
(defvar *server* nil)

(defvar *document* "/Users/vince/quicklisp/local-projects/sending-app/web/")

(defun start-server2 ()
  (start (setf *server* (make-instance 'easy-routes-acceptor
                       :document-root *document*
                       :port 8000))))
(defun stop-server ()
  (when *server*
    (stop *server*)
    (start-server2)))

;; ==== Djula Setup ==== ;;

(djula:add-template-directory *document*)

(defparameter *admin.html* (compile-template* "admin.html"))

(defroute admin ("/admin" :method :get) ()
  (render-template* *admin.html* nil
            :title "Project 2"))

project 2:

(in-package :project-two)

;; ==== Server Setup ==== ;;
(defvar *server* nil)

(defvar *document* "/Users/vince/quicklisp/local-projects/sales-web/web/")

(defun start-server2 ()
  (start (setf *server* (make-instance 'easy-routes-acceptor
                       :document-root *document*
                       :port 9000))))
(defun stop-server ()
  (when *server*
    (stop *server*)
    (start-server2)))

;; ==== Djula Setup ==== ;;

(djula:add-template-directory *document*)

(defparameter *admin.html* (compile-template* "admin.html"))

(defroute admin ("/admin" :method :get) ()
  (render-template* *admin.html* nil
            :title "Project 2"))


Solution

  • Routes are registered globally by default, you can add an :acceptor-name argument to defroute to make a route local to an acceptor. From the README:

    First you need to give your acceptor a name, using :name acceptor parameter:

    (hunchentoot:start (make-instance 'easy-routes:routes-acceptor :name
    'my-service))
    

    Then, use that name in routes definition :acceptor-name:

    (defroute my-route ("/my-route" :acceptor-name my-service)   ... )
    

    You can also define a local macro defroute* that expands to defroute with your preferred acceptor name in both projects.