aboutsummaryrefslogtreecommitdiff
path: root/lazybones.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lazybones.lisp')
-rw-r--r--lazybones.lisp18
1 files changed, 13 insertions, 5 deletions
diff --git a/lazybones.lisp b/lazybones.lisp
index ec3d032..9d55fcf 100644
--- a/lazybones.lisp
+++ b/lazybones.lisp
@@ -75,6 +75,12 @@
:initarg :vsn :initarg :version
:initform "0.0.1"
:type string)
+ (prefix
+ :accessor app-prefix
+ :initarg :prefix
+ :initform ""
+ :documentation "Effectively prepended to all endpoints for the
+ purposes of request handling. E.g. \"/api\" is a good prefix." )
(definitions
:accessor app-definitions
:initform (make-hash-table :test 'equal)
@@ -105,6 +111,7 @@
(list 'setf
(ecase option
((:desc :description) `(lazybones::app-description ,app))
+ (:prefix `(lazybones::app-prefix ,app))
(:title `(lazybones::app-title ,app))
(:version `(lazybones::app-version ,app))
(:content-type `(lazybones::default-content-type ,app))
@@ -207,11 +214,16 @@ list of values, in the case of success, or NIL in the case of failure."
into arguments
finally (return (or arguments t)))))
+(defun strip-app-prefix (app path)
+ (multiple-value-bind (success suffix) (a:starts-with-subseq (app-prefix app) path :return-suffix t)
+ (unless success (error "~a is not prefixed by ~a" path (app-prefix app)))
+ suffix))
+
(defun find-endpoint (app &optional (request *request*))
(find-endpoint-matching-key
app
(request-method request)
- (request-routekey request)))
+ (url-path->request-routekey (strip-app-prefix app (request-path request)))))
(defun method-match-for-dispatch-p (req-method ep-method)
"Either the arguments compare EQ or the first is :HEAD and the second is :GET."
@@ -256,10 +268,6 @@ ENDPOINT's handler function."
"A routekey is used to match urls to endpoints that handle them."
(str:split #\/ path))
-(defun request-routekey (request)
- (url-path->request-routekey
- (request-path request)))
-
(defun parse-route-string-template (template)
"Routes are of the form