Fix
This commit is contained in:
parent
68c3e0494d
commit
438030b0b8
2 changed files with 16 additions and 12 deletions
24
README.md
24
README.md
|
@ -24,23 +24,27 @@ To use ningle-fbr, you must use [package-inferred-system](https://asdf.common-li
|
||||||
(:nicknames #:example/app)
|
(:nicknames #:example/app)
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:import-from #:ningle)
|
(:import-from #:ningle)
|
||||||
(:import-from #:ningle-fbr))
|
(:import-from #:ningle-fbr
|
||||||
|
#:assign-routes))
|
||||||
(in-package #:example/app)
|
(in-package #:example/app)
|
||||||
|
|
||||||
(defparameter *app* (make-instance 'ningle:<app>))
|
(defparameter *app* (make-instance 'ningle:<app>))
|
||||||
|
|
||||||
(defun update-routes ()
|
(assign-routes *app*
|
||||||
(ningle-fbr:enable-file-based-routing
|
:directory "src/routes"
|
||||||
*app*
|
:system "example")
|
||||||
:directory "src/routes"
|
|
||||||
:system "example"))
|
|
||||||
|
|
||||||
(update-routes)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Static routing
|
## Static routing
|
||||||
|
|
||||||
`/src/routes/index.lisp` → `/`
|
`/src/routes/index.lisp` → `/`
|
||||||
|
|
||||||
|
`/src/routes/hello.lisp` → `/hello`
|
||||||
|
|
||||||
|
`/src/routes/users/index.lisp` → `/users`
|
||||||
|
|
||||||
|
`/src/routes/nested/page.lisp` → `/nested/page`
|
||||||
|
|
||||||
```lisp
|
```lisp
|
||||||
(uiop:define-package #:example/routes/index
|
(uiop:define-package #:example/routes/index
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
|
@ -67,9 +71,9 @@ To use ningle-fbr, you must use [package-inferred-system](https://asdf.common-li
|
||||||
|
|
||||||
A file or directory name prefixed with '=' indicates a dynamic path.
|
A file or directory name prefixed with '=' indicates a dynamic path.
|
||||||
|
|
||||||
In the example below, the name parameter can be obtained from handler's params.
|
In the example below, the parameter `id` can be obtained from handler's params.
|
||||||
|
|
||||||
`/src/routes/user/=name.lisp` → `/user/:name`
|
`/src/routes/user/=id.lisp` → `/user/:id`
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:local-nicknames (#:re #:cl-ppcre))
|
(:local-nicknames (#:re #:cl-ppcre))
|
||||||
(:local-nicknames (#:ng #:ningle))
|
(:local-nicknames (#:ng #:ningle))
|
||||||
(:export #:enable-file-based-routing))
|
(:export #:assign-routes))
|
||||||
(in-package :ningle-fbr)
|
(in-package :ningle-fbr)
|
||||||
|
|
||||||
(defun remove-file-type (namestr)
|
(defun remove-file-type (namestr)
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
(defparameter *http-request-methods*
|
(defparameter *http-request-methods*
|
||||||
'(:GET :POST :PUT :DELETE :HEAD :CONNECT :OPTIONS :PATCH))
|
'(:GET :POST :PUT :DELETE :HEAD :CONNECT :OPTIONS :PATCH))
|
||||||
|
|
||||||
(defun enable-file-based-routing (app &key directory system)
|
(defun assign-routes (app &key directory system)
|
||||||
(loop
|
(loop
|
||||||
:for (url . pkg) :in (dir->urls-and-packages directory system)
|
:for (url . pkg) :in (dir->urls-and-packages directory system)
|
||||||
:do (ql:quickload pkg)
|
:do (ql:quickload pkg)
|
||||||
|
|
Loading…
Reference in a new issue