我正在使用 ningle 框架开发一个 Web 应用程序,基本上,我的 asd 看起来像这样:
(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)))
使用 LEM 编辑器,如果我执行
asdf:load-system :rest-api
,它会加载项目并且它可以工作,我可以通过访问我的应用程序路由来检查它,但是,如果我执行 sbcl --script "~/quicklisp/setup.lisp"
后跟 (asdf:load-system :rest-api)
,即使它有效,它只运行主文件,所以路由不起作用。
我的路线是这样的:
(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))))
这是我的 main.lisp 文件,加上函数是入口点。我不知道我做错了什么。
(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)
Asdf 使用一组称为配置变量的指令来查找和加载系统文件。如果这些说明中有任何错误,asdf 可能无法正确加载文件。
某些 asdf 系统需要其他系统或库才能工作。如果缺少其中任何一个,asdf 可能无法正确加载系统。
asdf 或 SBCL 中也可能存在错误,导致 asdf 无法正确加载文件。