Comments (13)
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()
}
}
from lua-resty-route.
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,
})
from lua-resty-route.
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.
from lua-resty-route.
+1, can you please add some examples?
from lua-resty-route.
@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.
from lua-resty-route.
Thanks !
from lua-resty-route.
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
from lua-resty-route.
@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).
from lua-resty-route.
@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
from lua-resty-route.
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)
from lua-resty-route.
@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.
from lua-resty-route.
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.
from lua-resty-route.
hello,this repo is still being maintained ? looking forward to see this package on opm
from lua-resty-route.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-resty-route.