APItools / router.lua

A barebones router for Lua. It matches urls and executes lua functions.
MIT License
195 stars 47 forks source link

query param support? #10

Open viliman opened 9 years ago

viliman commented 9 years ago

I've given this a try now and like it much. However, it is unclear to me how this works with query parameters? There was example with POST but I would like to use with GET and query params such as /hello?name=Peter is this possible?

viliman commented 9 years ago

The problem was that the query params mixed the matching in router.lua

So I removed them from the URI that was feeding the router.. with following workaround code: local uri = ngx.var.request_uri local uri_without_query_params local from, to, err = ngx.re.find(uri, "([^?.]+)") if from then ngx.say("from: ", from) ngx.say("to: ", to) uri_without_query_params = string.sub(uri, from, to) ngx.say("matched: ", uri_without_query_params) else if err then ngx.say("error: ", err) return end ngx.say("not matched!") end

-- Echo the ngix requests to router module if r:execute( ngx.var.request_method, uri_without_query_params, ngx.req.get_uri_args() ) then ngx.status = 200 else ngx.status = 404 ngx.print("Not found!") end

rohitjoshi commented 8 years ago

I had the same issue and submitted below PR which will fix this issue. https://github.com/APItools/router.lua/pull/14

rohitjoshi commented 8 years ago

alternate option is to use ngx.var.uri instead of ngx.var.request_uri or your local variable uri_without_query_params

viliman commented 8 years ago

Thanks for info and the fix!