mirror of
https://github.com/urlysses/1991.git
synced 2024-12-29 19:18:07 +11:00
Finalize url mapping/url pattern matching.
All that was missing in 574c33c27e
was a
way to retreive the values of our fuzzy matches.
This commit is contained in:
parent
574c33c27e
commit
7ff8c9942e
62
1991.fs
62
1991.fs
@ -38,6 +38,33 @@ include unix/socket.fs
|
||||
2dup file-status nip 0= ;
|
||||
: pubvar create 0 , 0 , ;
|
||||
|
||||
\ Query params
|
||||
pubvar queryString
|
||||
: set-query-string ( addr u -- )
|
||||
queryString 2! ;
|
||||
: get-query-string ( -- addr u )
|
||||
queryString 2@ ;
|
||||
: add-to-query-string ( addr u -- )
|
||||
get-query-string
|
||||
dup if \ If queryString isn't empty, add & before
|
||||
s" &" s+
|
||||
then
|
||||
+s \ adding our new query values.
|
||||
set-query-string ;
|
||||
|
||||
pubvar tmpQueryString
|
||||
: set-tmp-query-string ( addr u -- )
|
||||
tmpQueryString 2! ;
|
||||
: get-tmp-query-string ( -- addr u )
|
||||
tmpQueryString 2@ ;
|
||||
: add-to-tmp-query-string ( addr u -- )
|
||||
get-tmp-query-string
|
||||
dup if \ If queryString isn't empty, add & before
|
||||
s" &" s+
|
||||
then
|
||||
+s \ adding our new query values.
|
||||
set-tmp-query-string ;
|
||||
|
||||
\ User-defined routing
|
||||
wordlist constant routes
|
||||
pubvar reqroute
|
||||
@ -61,6 +88,9 @@ pubvar reqroute
|
||||
then
|
||||
rdrop
|
||||
?dup if
|
||||
get-tmp-query-string \ Save our fuzzy vars to the request's
|
||||
add-to-query-string \ query real string.
|
||||
|
||||
name>int \ Get the xt of the nt.
|
||||
-1 \ Return true.
|
||||
else
|
||||
@ -70,6 +100,7 @@ pubvar reqroute
|
||||
\ Takes a route name token and returns
|
||||
\ whether that route name fuzzy matches
|
||||
\ the requested url
|
||||
s" " set-tmp-query-string \ Reset tmp query string.
|
||||
name>string \ Get the string value of the NT.
|
||||
2dup s" <" search if \ See if the route expects fuzzy matching.
|
||||
2drop \ Drop search results.
|
||||
@ -88,15 +119,27 @@ pubvar reqroute
|
||||
else
|
||||
2drop
|
||||
then
|
||||
\ (
|
||||
2dup 2r> 2swap 2>r 2>r \ (Store a copy of the real value of <match>.)
|
||||
\ )
|
||||
2r@
|
||||
2dup s" <" search drop \ and replace <...> with the requested route word
|
||||
swap drop -
|
||||
swap drop
|
||||
\ (
|
||||
over over - 1+ 2r@ rot /string \ (Store the beginnings of user's <"match"> word.)
|
||||
2dup s" >" search drop \ (Retrieve full <"match"> user word,)
|
||||
swap drop - s" =" s+
|
||||
2r> 2r> 2swap 2>r
|
||||
s+ \ (and associate it with the request value,)
|
||||
add-to-tmp-query-string \ (before saving it to the tmp query string.)
|
||||
\ )
|
||||
-
|
||||
+s \ by prepending pre-< to route word
|
||||
2r> s" >" search drop 1 /string \ and then by appending post-> to route word.
|
||||
s+
|
||||
2>r
|
||||
2drop
|
||||
2r>
|
||||
2>r \ Save string progress,
|
||||
2drop \ drop old string,
|
||||
2r> \ set new string for start of next loop (or end).
|
||||
loop
|
||||
get-requested-route compare \ Check to see if the strings match.
|
||||
else
|
||||
@ -222,13 +265,6 @@ pubvar viewoutput
|
||||
s" "
|
||||
then ;
|
||||
|
||||
\ Query params
|
||||
pubvar queryString
|
||||
: set-query-string ( addr u -- )
|
||||
queryString 2! ;
|
||||
: get-query-string ( -- addr u )
|
||||
queryString 2@ ;
|
||||
|
||||
\ Request's Content-Type
|
||||
pubvar RequestContentType
|
||||
: set-content-type ( addr u -- )
|
||||
@ -289,10 +325,10 @@ s" image/x-icon" filetype: ico
|
||||
|
||||
: store-query-string ( addr u -- raddr ru )
|
||||
2dup s" ?" search if
|
||||
2dup set-query-string \ store query string
|
||||
2dup 1 /string set-query-string \ Store query string (without leading "?").
|
||||
swap drop -
|
||||
else
|
||||
s" " set-query-string \ store empty query string (reset)
|
||||
s" " set-query-string \ Store empty query string (reset).
|
||||
2drop
|
||||
then ;
|
||||
|
||||
|
@ -10,4 +10,4 @@ unless otherwise specified by user.
|
||||
+ [x] query arguments
|
||||
+ [ ] PUT, POST, DELETE
|
||||
+ [x] templating
|
||||
+ [ ] fuzzy-/pattern-match-enabled user routes (e.g., /something/*/wildcard)?
|
||||
+ [x] fuzzy-/pattern-match-enabled user routes (e.g., /something/*/wildcard)?
|
||||
|
@ -21,17 +21,17 @@ sourcedir s" views/" s+ set-view-path
|
||||
/1991 /import handle-import
|
||||
|
||||
: handle-uid
|
||||
s" uid:" ;
|
||||
s" uid:" get-query-string s+ ;
|
||||
: handle-uid-new
|
||||
s" uid:new" ;
|
||||
s" uid:new:" get-query-string s+ ;
|
||||
: handle-uid-delete
|
||||
s" uid:delete" ;
|
||||
s" uid:delete:" get-query-string s+ ;
|
||||
: handle-pid
|
||||
s" pid:" ;
|
||||
s" pid:" get-query-string s+ ;
|
||||
: handle-pid-new
|
||||
s" pid:new" ;
|
||||
s" pid:new:" get-query-string s+ ;
|
||||
: handle-pid-delete
|
||||
s" pid:delete" ;
|
||||
s" pid:delete:" get-query-string s+ ;
|
||||
/1991 /api/v1/users/<uid> handle-uid
|
||||
/1991 /api/v1/users/<uid>/new handle-uid-new
|
||||
/1991 /api/v1/users/<uid>/delete handle-uid-delete
|
||||
|
Loading…
Reference in New Issue
Block a user