asdf doesn't load files properly in sbcl, but it loads files properly in repl

88 Views Asked by At

I'm developing a web application using the ningle framework, basically, my asd looks like that:

(defsystem "rest-api"
  :version "0.1.0"
  :defsystem-depends-on (:deploy)
  :build-operation "deploy-op"
  :build-pathname "rest-api"
  :entry-point "rest-api::main"
  :author ""
  :license ""
  :depends-on (#:clack
               #:ningle
               #:mito
               #:yason
               #:ironclad
               #:jose
               #:clack-handler-hunchentoot)
  :components ((:module "src"
                :components
                ((:file "main")
                 (:module "model"
                  :components ((:file "user")
                               (:file "admin")))
                 (:module "controller"
                  :components ((:file "user-controller")))
                 (:module "service"
                  :components ((:file "user-service")
                               (:file "auth-service")))
                 (:module "utils"
                  :components ((:file "json-util")))
                 )))
  :description ""
  :in-order-to ((test-op (test-op "rest-api/tests"))))

(defsystem "rest-api/tests"
  :author ""
  :license ""
  :depends-on ("rest-api"
               "rove")
  :components ((:module "tests"
                :components
                ((:file "main"))))
  :description "Test system for rest-api"
  :perform (test-op (op c) (symbol-call :rove :run c)))

Using the LEM editor, if I do asdf:load-system :rest-api, it loads the project and it works, which I can check by accessing my app routes, however, if I do sbcl --script "~/quicklisp/setup.lisp" followed by (asdf:load-system :rest-api), even though it works, it only runs the main file, so the routes don't work.

My routes look like that:

(defpackage user-controller
  (:use :cl))
(in-package :rest-api)

(setf (ningle:route *app* "/user/sign-up" :method :POST)
      #'(lambda (params)
          (user-create params)))

(setf (ningle:route *app* "/user/:id" :method :GET)
      #'(lambda (params)
          (yason:with-output-to-string* () (yason:encode-object (user-read params)))))

(setf (ningle:route *app* "/user/login" :method :POST)
      #'(lambda (params)
          (format nil "~A" (user-login params))))

(setf (ningle:route *app* "/user/:id" :method :PUT)
      #'(lambda (params)
          (with-user-permission-validation ningle:*request* params
            (user-update params))))

(setf (ningle:route *app* "/user/:id" :method :DELETE)
      #'(lambda (params)
          (with-user-permission-validation ningle:*request*
              (user-soft-delete params))))

and this is my main.lisp file, plus the function is the entry point. I don't know what I am doing wrong.

(defpackage rest-api
  (:use :cl))
(in-package :rest-api)

(mito:connect-toplevel :sqlite3 :database-name "rest-api.db")
(setf mito:*auto-migration-mode* t)
(setf mito:*migration-keep-temp-tables* nil)

(defvar *key* (ironclad:ascii-string-to-byte-array "secret"))

(defvar *app* (make-instance 'ningle:app))
(defvar *server* nil)

(defun main () 
  (setf *server* (clack:clackup *app* :address "0.0.0.0"))

(handler-case (bt:join-thread (find-if (lambda (th)
                                         (search "hunchentoot"
                                                 (bt:thread-name th)))
                                       (bt:all-threads)))
  ;; Catch a user's C-c
  (#+sbcl sb-sys:interactive-interrupt
   #+ccl  ccl:interrupt-signal-condition
   #+clisp system::simple-interrupt-condition
   #+ecl ext:interactive-interrupt
   #+allegro excl:interrupt-signal
    ()
    (progn
      (format *error-output* "Aborting.~&")
      (clack:stop *server*)
      (uiop:quit)))
  (error (c) (format t "Woops, an unknown error occured:~&~a~&" c))))

(main)
0

There are 0 best solutions below