-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hello,how to use this module? #1
Comments
Well, this is still work-in-progress. That doesn't say it is totally un-usable, but it is hard to describe it totally here in comment. So I don't try. I will keep you updated as soon as I get this finished. It is almost there, but some parts still need some adjustments. |
+1, can you please add some examples? |
@saucisson, what kind of examples are you looking for? There are some documentation added since @winfan opened this. I'm trying to finish initial docs shortly, but I have been quite busy lately. |
For instance, how do you effectively execute routes within an openresty location? local Route = require "resty.route"
local route = Route.new ()
route:get ("/", function (self)
...
end)
return function ()
route:dispatch (ngx.var.request_uri, ngx.var.request_method)
end and in
Also for the Redis middleware, why do you return a function taking the configuration as parameter? local Redis = require "resty.redis"
local redis = function (options)
return function (self)
local r, e = Redis:new()
if not r then
return self.route:error(e)
end
local o, e = r:connect(options.host, options.port)
if not o then
return self.route:error(e)
end
if options.timeout then
r:set_timeout(options.timeout)
end
self.redis = r
coroutine.yield ()
if options.max_idle_timeout and options.pool_size then
r:set_keepalive(options.max_idle_timeout, options.pool_size)
else
r:close()
end
end
end
route:use (redis {
host = redis_url.host,
port = redis_url.port,
}) |
On road map there is: The current ones are not designed to work with this. They are for older one. I'm sorry. Please don't use included middleware now, but you may write your own. The basic idea is this: Nginx init: init_by_lua_block {
require "routes"
} routes.lua: local route = require "resty.route".new()
route:get ("/", function(self)
-- ...
end)
route:get ("=/test", function(self)
-- ...
end)
return route Nginx location: location / {
content_by_lua_block {
require "routes":dispatch()
}
} |
Thanks ! |
hey bungle, would you add the configuration details in Readme as you did in comment? That will be much helpful to new openresty users. Best, |
@donglaizhang, I will do it. Thank you for the interest. If any of you would like to go on and improve this library or documentation, I'm open to pull requests. I wish that I have some time to go through the some of the remaining items that I think needs to be there (e.g. rewrite the websockets handler and middlewares). |
@bungle Looking forward to your reply, thanks |
I can see that you have put in a lot of thought and efforts in building this module. I like the way you are going crazy with routes! I appreciate you releasing it. I am wondering how I can use it with various phases of *_by_lua_block (such as rewrite_by_lua_block, access_by_lua_block, etc) |
@bumi001 right now I think you should build a router for each. Currently there is no specific code to handle phases, although that would be interesting to do. I really need to get some time to continue this work. In a meanwhile, all the help and PRs are appreciated. |
Thank you for your reply. Building a router for each phase makes perfect sense. Handling phases from a single router is probably not the right approach, I think. |
hello,this repo is still being maintained ? looking forward to see this package on opm |
hello,how to use this module?
The text was updated successfully, but these errors were encountered: