Skip to content
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

Open
ltanme opened this issue Nov 23, 2016 · 13 comments
Open

hello,how to use this module? #1

ltanme opened this issue Nov 23, 2016 · 13 comments

Comments

@ltanme
Copy link

ltanme commented Nov 23, 2016

hello,how to use this module?

@bungle
Copy link
Owner

bungle commented Nov 23, 2016

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.

@saucisson
Copy link

+1, can you please add some examples?

@bungle
Copy link
Owner

bungle commented Mar 8, 2017

@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.

@saucisson
Copy link

saucisson commented Mar 8, 2017

For instance, how do you effectively execute routes within an openresty location?
Looking at the sources, i have tried the following code, but it might be incorrect:

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 nginx.conf

location @mylocation {
  content_by_lua_block {
    require "resty.core"
    local server = require "myserver"
    server () -- server is the function returned in the listing above
  }
}

Also for the Redis middleware, why do you return a function taking the configuration as parameter?
I have managed to make something work by inverting the two nested functions of the middleware, but it does not seem to be what is expected in your library:

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,
})

@bungle
Copy link
Owner

bungle commented Mar 8, 2017

@saucisson,

On road map there is:
Rewrite current middleware and add new ones
https://github.com/bungle/lua-resty-route#roadmap

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()
    }
}

@saucisson
Copy link

Thanks !

@donglaizhang
Copy link

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,
Donglai

@bungle
Copy link
Owner

bungle commented Mar 16, 2017

@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).

@jingb
Copy link

jingb commented May 1, 2017

@bungle
Hi bungle.
I used "opm serach route" to search the repo but it return "nothing found".
So the only way to use this repo is to download the source and put it into the location OPENRESTY_HOME/lualib/resty right ?

Looking forward to your reply, thanks

@bumi001
Copy link

bumi001 commented Aug 26, 2018

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)

@bungle
Copy link
Owner

bungle commented Aug 27, 2018

@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.

@bumi001
Copy link

bumi001 commented Sep 6, 2018

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.

@hi-glenn
Copy link

hello,this repo is still being maintained ? looking forward to see this package on opm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants