commit d55d697d756550a477d17f1f37eaa10c1f38d4f0
parent 8ff9da518df8f352ffbda2686a5135bebbae3b0c
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 20 Jul 2025 20:18:38 +0100
route-request accepts method and path
Diffstat:
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/main.fnl b/main.fnl
@@ -116,7 +116,7 @@
(local handlers
[
- #(if (= $1 "/")
+ #(if (= $2 "/")
{
:command :search
:format :summaries
@@ -124,7 +124,7 @@
:order {:date :descending}
:offset 0
})
- #(case (string.match $1 "/(%d+)/(%d+)/" 1)
+ #(case (string.match $2 "/(%d+)/(%d+)/" 1)
(year month)
(let [after (os.time {: year : month :day -2 })
before (os.time {: year :month (+ month 1) :day 2 })]
@@ -136,19 +136,19 @@
:offset 0
}))
- #(case (string.match $1 "/([%w_]+)$" 1)
+ #(case (string.match $2 "/([%w_]+)$" 1)
slug { :command :show :format :html : slug })
])
-(fn route-request [path]
+(fn route-request [method path]
(accumulate [matched nil
_ pred (ipairs handlers)
&until matched]
- (pred path)))
+ (pred method path)))
(define-tests :route-request
- (expect= (route-request "/")
+ (expect= (route-request :get "/")
{
:command :search
:format :summaries
@@ -157,14 +157,14 @@
:offset 0
})
- (expect= (route-request "/pagename")
+ (expect= (route-request :get "/pagename")
{
:command :show
:format :html
:slug "pagename"
})
- (expect= (route-request "/2004/7/")
+ (expect= (route-request :get "/2004/7/")
{
:command :search
:format :html