Giter Club home page Giter Club logo

lor's People

Contributors

hanxi avatar lhmwzy avatar lifeblood avatar lihuibin avatar ms2008 avatar noname007 avatar sumory avatar syhily avatar vinsonzou avatar wanghaisheng avatar wtkb avatar wuyachao avatar xadillax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lor's Issues

如何debug?

请教一下,如果想在router里面打印一些调试信息要如何做呢?
尝试过用ngx.log但是并没有打印出来,也没输出到日志。

多个中间件有执行顺序的要求,当某个中间件含有多个next()时,执行顺序有问题

    -- 作用于所有请求
    app:use(function(req, res, next)
       ngx.log(ngx.ERR, "all middleware 1")
       local a = xxx
       if a then
         next()
       end
        next()    
    end)
    app:use(function(req, res, next)
        ngx.log(ngx.ERR, "all middleware 2")
        next()
    end)

问题如上:期望是先执行middleware 1,后执行2,当middleware 的变量a为ture时,执行顺序会是1--2--1,即middleware 被执行了多次,如何避免这种情况?尝试a为true时return,刷新页面有下载行为,不知道为什么

不使用start.sh启动,如何在原有的nginx添加新站点

我的服务器已经有其他站点在运行
我怎样在原有的nginx里添加一个lor的站点?
我不可能停用其他的站点,使用lord start启用新的站点啊

我添加以下配置,站点无法访问,报500错误,但是访问html页面是可以的

# user www www;
pid logs/dev-nginx.pid;

# This number should be at maxium the number of CPU on the server
worker_processes 1;

events {
    # Number of connections per worker
    worker_connections 1024;
}

http {
    include       mime.types;
    # use sendfile
    sendfile on;
    # include #NGX_PATH/conf/mime.types;

    # lor initialization
    lua_package_path "/home/www/lor_demo/app/?.lua;/home/www/lor_demo/app/library/?.lua;/home/www/lor_demo/app/?/init.lua;/home/www/lor_demo/?.lua;/usr/local/lor//?.lua;/usr/local/lor//?/init.lua;;";
    lua_package_cpath "/home/www/lor_demo/app/library/?.so;/usr/local/lor//?.so;;";
    lua_code_cache off;
    #LUA_SHARED_DICT

   keepalive_timeout  65; 

    server {
        # List port
        listen 80;
    server_name lordemo.lua.com;

        #set $template_root '';

        location /static {
            alias /home/www/lor_demo/app/static; #app/static;
        }

        # Access log with buffer, or disable it completetely if unneeded
        access_log logs/dev-access.log combined buffer=16k;
        # access_log off;

        # Error log
        error_log logs/dev-error.log;

        # lor runtime
        location / {
            content_by_lua_file /home/www/lor_demo/app/main.lua;
        }

    # location / {
        #    root   /home/www/lor_demo/;
        #    index  index.html index.htm;
       # }
    }
}

关于/user和/user/两种类型的URI

假设我们有一个group router user_router,它挂载在"user"下面,即

app:use("user", user_router())

lor v0.3.0版本并不支持在这个group router里实现"/user"这个路由,即不支持以下写法:

user_router:get("", function(req, rex, next) 
     --
end)

但支持将路由挂载到"/user/",即支持:

user_router:get("/", function(req, rex, next) 
     --
end)

从语义上来讲,/user/user/并不等价,只是有些应用服务器或是语言对此作了默认处理。

在lor v0.3.0的实现中,认为/user属于全局对象的,即应该通过app:get("/user", ...)来挂载到app上,而/user/属于上面所说的user_router,即应该通过user_router:get("/", ...)挂载到user_router上。

此外lor提供了两种路由模式来配置是否将"/user"和"/user/"作为等价路由,详细请参看这篇文章


在下个版本v0.3.1中会实现类似如下写法来满足习惯用法,即将/user挂载到user_router下面:

user_router:get(function(req, res, next)
    res:send("this is /user")
end)

关于自定义的erruse

我在demo的app/routes/user.lua里加入了
app:erroruse("/user", function(req, res, next) ngx.log(ngx.ERR, "@@debug_info@@:in my err handler.") next() end)
企图捕获/user/路径下的err但是我输入一些列的/user下的错误
如:curl "127.0.0.1/user/query1",curl -X POST "127.0.0.1/user/create13?name=12&id=13",都是落入app/server.lua下定义的全路径的erroruse,当我注释掉server.lua下的这个erroruse,就会报错说application.lua:84: handle(): 404! not found.我又尝试把自定义的erroruse挪到server.lua里的默认erroruse的前面和后面都还是只会落入到默认的erroruse里,我也尝试过在默认的erroruse里加入next(),也是无济于事.

如何取得response中的headers

router:get("/getinfo/",function(req,res,next)
             local response = res:get_headers()
            ngx.say(" response ",response)
end)

上面这段代码取得的response变量是nil.

proxy

Hi,
我正在用lor参照openresty-china的例子写一个server,我想用lor实现用户登陆和认证,然后保持我之前后台的application server不变,认证成功之后把http请求转给后台的app server,实现之前在nginx里的
proxy_pass http://localhost:7000;

我现在的做法是在lua部分认证成功后用res:redirect, router部分代码如下:
local lor = require("lor.index")
local painter_router = lor:Router()

painter_router:post("/upload", function(req, res, next)
ngx.log(ngx.DEBUG, "redirecting upload...")
return res:redirect("/Tornado/upload")
end)

return painter_router
在router处理这部分之前有 app:use(check_login_middleware(whitelist)),跟openresty-china中的类似。

相应的nginx.conf的部分是
location /Tornado {
internal;
proxy_pass http://localhost:7000;
}

这样做遇到两个问题:

  1. 是如果我把这个location设置为internal,将返回404 not found,但是我不想把这个接口暴露出来,因为是需要认证成功之后才能使用的;
  2. 是如果去掉internal,后台可以收到请求,但是请求类型变成了GET而不是原来的POST。

请问怎么可以做到认证成功后作为代理将请求转发给后台的app server处理,而且不把后台暴露出来呢?

谢谢!

little problem

lua entry thread aborted: runtime error: /usr/local/lor/lor/lib/request.lua:17: bad argument #1 to 'sfind' (string expected, got table) stack traceback: coroutine 0: [C]: in function 'sfind' /usr/local/lor/lor/lib/request.lua:17: in function 'new' /usr/local/lor/lor/lib/application.lua:37: in function 'run'

/usr/bin/env: ‘resty’: No such file or directory

在安装lor时,执行lord path后报这个异常,我找遍了openresty都没发现有resty之个目录,反而在lor_master(下载的源文件目录)及/usr/local/lor下找到一个resty目录,添加到环境变量后依家不行。

我的openresty版本是:nginx version: openresty/1.13.6.1

在openresty目录 下没找到resty目录

如何对单个 router 添加统一的检测函数

类似于 middleware, 作用于单个 router。如下代码,我想要的是在此 user_router 下的所有方法执行前先执行统一判断用户是否登录。

local lor = require "lor.index"
local user_router = lor:Router()

user_router:use('/', function (req, res, next)
    local user_session = req.session.get("user")
    if not user_session then
        return res:json({
            success = false,
            msg = "未登录!",
            error_code = "NOT_LOGIN"
        })
    end
    next()
end, 3)

user_router:get("/info", function(req, res, next)
    local user_session = req.session.get("user")
    ngx.log(ngx.DEBUG, "info:", user_session.userid)

    return res:json({
        success = true,
        msg = "userinfo."
    })
end)


return user_router

bug in resty.template, version issue?

now the version of resty.template in lor () is 1.6-dev, it should be updated to the latest version 1.9,
because i got a bug in using template blocks.

nginx启动出现cordump

使用demo示例 nginx启动出现cordump

/data/corefile/core_nginx_1478829514.843
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-suse-linux"...
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `/usr/local/openresty/nginx/sbin/nginx'.
Program terminated with signal 8, Arithmetic exception.
#0 0x00002acb9e8c980f in _start () at rtld.c:784
784 rtld.c: No such file or directory.
in rtld.c
(gdb) bt
#0 0x00002acb9e8c980f in _start () at rtld.c:784
#1 0x00007fff0c1e3e4f in ?? ()
#2 0x000000000000000

操作系统 suse 10.1 64位 内核版本 2.6.16.60-0.21

openresty 版本
resty 0.12
nginx version: openresty/1.9.15.1
built by gcc 4.1.2 20070115 (prerelease) (SUSE Linux)
built with OpenSSL 1.0.2j 26 Sep 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.59 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.30 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.05 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.5 --add-module=../ngx_lua_upstream-0.05 --add-module=../headers-more-nginx-module-0.30 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre=/data/michaellin/tool/pcre-8.35 --with-openssl=/data/michaellin/tool/openssl-1.0.2j --with-http_ssl_module

当出现这种情况的时候

execute: nginx  -g "env LOR_ENV=dev;" -p `pwd`/ -c conf/nginx-dev.conf
nginx: [emerg] unknown directive "lua_package_path" in /var/www/

应该使用修改 start.sh 这个文件:
nginx -p pwd/ -c conf/nginx-${PROFILE}.conf
改成 openresty -p pwd/ -c conf/nginx-${PROFILE}.conf

perf issue ?

hello,
i've just benchmarked a bare OpenResty and Lor "Hello World" (generated by lord new) with same worker/ max connection config. I've found a nearly 10x times request/sec difference between them. Any idea ?

/usr/bin/env: resty: No such file or directory

use order: lua /usr/local/bin/lord -h

$ lua /usr/local/bin/lord
lor v0.2.6, a Lua web framework based on OpenResty.

Usage: lord COMMAND [OPTIONS]

Commands:
 new [name]             Create a new application
 start                  Start the server
 stop                   Stop the server
 restart                Restart the server
 version                Show version of lor
 help                   Show help tips
 path                   Show install path

启动lor错误

代码lor/bin/scaffold/launcher.lua中第60行

local result = handler:start(env)

实际测试返回值为boolean类型,下面一行代码判断错误,导致lor启动报错

English Docs

Is there any plans to translate docs to english? This framework seems like the perfect fit for my current project, but I barely understand anything.

New lor cli backend

resty-cli is a very useful interpreter better than LuaJIT. New CLI based on resty-cli would gives more power and flexibility to lor users and allow for an easier integration in deployment workflow. This would also replace the start.sh & shutdown.sh scripts.

多级处理函数中,如果中间有nil方法.将造成异常结束且无任何提示和报错

使用如下代码,其中util.auth_ip是一个通用写好的且存在的校验访问ip是否合法的方法
util.auth_jsonbody是一个nil

local user_router = lor:Router()
user_router:get("/test", util.auth_ip,util.auth_jsonbody,function(req, res, next)
res:status(200):send("unknown error")
end)
app:use("/cloud/v1", user_router())
app:run()
curl -v http://127.0.0.1:4001/cloud/v1/test
* About to connect() to 127.0.0.1 port 4001 (#0)
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 4001 (#0)
> GET /cloud/v1/test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:4001
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: openresty
< Date: Fri, 16 Mar 2018 07:10:39 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< 
* Connection #0 to host 127.0.0.1 left intact

200状态码返回,但是没有任何body,日志中也无任何错误提示
显然不符合预期

stack traceback print while processing request

Hello:
I want to get some debug info from nginx log file, especially the lua stack traceback. However the handling function runs under the 'xpcall' protection.
I tried to opened the debug mode of lor in my app:

local app = lor({debug = true})

but got the errors as follows:

[error] 11080#0: *7282 lua entry thread aborted: runtime error: ./lor/lib/debug.lua:20: bad argument #2 to 'print' (string, number, boolean, or nil expected, got table)

It is seemed lor's debug mode is uesd for busted

    debug("handle_request:call error", ok, e, ee) 

Can lor supports the trackback info in nginx log via ngx.log api like this:

lor/lib/router/layer.lua, line 124.

if not ok then
    debug("handle_request:call error", ok, e, ee)
    ngx.log(ngx.ERR, "handle_request:call error", ok, e, ee)
    next(e or ee)
end

Thanks!

Auto generate API doc by lor specification

Lor is easy to expose a restful api for backend management.
It would be nice to have a cli helper to generate api doc.
I would recommend Swagger JSON format, because it would be parsed and have a nice test interface.

建议把reload.sh里的-s reload的方式替换为kill -HUP `cat tmp/dev-nginx.pid`

今天测试cosocket的连接池的时候发现修改lua_code_cache off/on,然后使用reload的时候,cosocket连接池不会跟着新的lua VM走.也就是cosocket应该是跟lua VM绑定的,lua_code_cache off的时候,cosocket连接池会跟着具有单次请求生命期的lua VM一起销毁,这种情况下抓包也确实证明了这一点,但是当修改lua_code_cache on并且reload的时候,抓包发现cosocket连接池还是同样只具有单次请求的生命期;而结束进程,保持lua_code_cache on的情况下重新启动,cosocket连接池却是正常的全局lua VM的生命期.上述测试中把reload的方式替换为kill -HUP cat tmp/dev-nginx.pid,这个时候抓包发现,cosocket连接池能够正常的切换到全局的lua VM,而且查阅资料,春哥和NGX官方都有提到"-s reload的引入主要是为了支持Windows 系统,在UNIX风格的系统上可以基本工作,但容易引起一些问题.",所以建议建议把reload.sh里的-s reload的方式替换为kill -HUP cat tmp/dev-nginx.pid.
发出来之前最后一次测试,发现-s reload还会再次调用init_by_lua,这个对于在这里初始化一些全局变量的做法应该是伤害挺大的吧.

无法自定义设置cookie的问题.

大家好, 我这里有一个需求就是,如果一个request 没有带Cookie来访问,我这边的服务器就打上Set-Cookie,他如果带有效的Cookie来访问服务器检查并通过.我下面的这个代码片段,设置不了reponse的Cookie,并且日志报错.我这些代码是fork https://github.com/sumory/openresty-china,并且我用curl 测这个服务,不管request 有没带Cookie请求,这个服务器都会返一个新的Cookie ,新的sessionid .

local ckobj = require "lor.resty.cookie"
[...]
router:get("/getinfo",function(req,res,next)

            res.cookie = ckobj:new()
            local ok,err = res.cookie:set({
               sessionid = get_new_cookie(),
               httponly = true,
               expire = 600,
               Path="/" })
          return res:json({ok=true})

end)
[...]

调试错误如下:

2017/01/09 14:37:05 [error] 1574#0: *493 attempt to set ngx.header.HEADER after sending out response headers, client: 192.168.8.31, server: , request: "GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1", host: "127.0.0.1:8888"
2017/01/09 14:37:05 [error] 1574#0: *493 attempt to set ngx.header.HEADER after sending out response headers, client: 192.168.8.31, server: , request: "GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1", host: "127.0.0.1:8888"
2017/01/09 14:37:05 [error] 1574#0: *493 attempt to set ngx.status after sending out response headers, client: 192.168.8.31, server: , request: "GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1", host: "127.0.0.1:8888"
2017/01/09 14:37:14 [error] 1575#0: *496 [lua] main.lua:19:  package for lor is ./app/lor/lor/index.lua, client: 192.168.8.31, server: , request: "GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1", host: "127.0.0.1:8888"
2017/01/09 14:37:14 [error] 1575#0: *496 attempt to set ngx.header.HEADER after sending out response headers, client: 192.168.8.31, server: , request: "GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1", host: "127.0.0.1:8888"
2017/01/09 14:37:14 [error] 1575#0: *496 attempt to set ngx.header.HEADER after sending out response headers, client: 192.168.8.31, server: , request: "GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1", host: "127.0.0.1:8888"
2017/01/09 14:37:14 [error] 1575#0: *496 attempt to set ngx.status after sending out response headers, client: 192.168.8.31, server: , request: "GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1", host: "127.0.0.1:8888"

Set-Cookie 的问题.

curl -v http://127.0.0.1:8888/iot/v1.0/app/auth/abc/123456/ -b "session=hW0X8q9k0PjoLe_bMVEyMA..|1483689794|jpsJApDD59qI9hcb6oM4vA..|EFDCyDPBZ1IrL7dSB6JctRWSawo.; Expires=Fri, 06 Jan 2017 08:03:14 GMT; Max-Age=3600; Path=/; SameSite=Lax; HttpOnly"
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8888 (#0)
> GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 127.0.0.1:8888
> Accept: */*
> Cookie: session=hW0X8q9k0PjoLe_bMVEyMA..|1483689794|jpsJApDD59qI9hcb6oM4vA..|EFDCyDPBZ1IrL7dSB6JctRWSawo.; Expires=Fri, 06 Jan 2017 08:03:14 GMT; Max-Age=3600; Path=/; SameSite=Lax; HttpOnly
> 
< HTTP/1.1 200 OK
* Server openresty/1.11.2.1 is not blacklisted
< Server: openresty/1.11.2.1
< Date: Fri, 06 Jan 2017 07:03:39 GMT
< Content-Type: text/plain; charset=utf8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: session=_DJqHt044CATcklg0wqc5Q..|1483689819|PIw1d7OsefTYWNO_0lKU5g..|9JYBHjc9pmF1v-CtVZxc0YbsNuI.; Expires=Fri, 06 Jan 2017 08:03:39 GMT; Max-Age=3600; Path=/; SameSite=Lax; HttpOnly
< X-Powered-By: Lor Framework
< 
 get data nil
debug  print table: 0x401ee088
 head is 
{"srvs":"127.0.0.10:1883","uuid":"f1852fcde4294f8c917522a12ec25fd1","time":"1483686219","sign":"D67CB6FE79412DC73B92E2EC5568C5C78B7FA76A","expire":600,"ok":true}
* Connection #0 to host 127.0.0.1 left intact

为什么,请求带了Cookie,服务器还是会返回Set-Cookie?有没有方法像Django一样,如果请求里没有Cookie,或者Cookie已经过期,就在返回里加上Set-Cookie.

下面是Django的实例

 curl -v http://127.0.0.1:8000/iot/v1.0/app/auth/abc/123456/ 
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 127.0.0.1:8000
> Accept: */*

* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Fri, 06 Jan 2017 07:08:45 GMT
< Server: WSGIServer/0.1 Python/2.7.10
< Vary: Cookie
< X-Frame-Options: SAMEORIGIN
< Content-Type: application/json; charset=utf-8
< Set-Cookie:  sessionid=1tvksaww96ggfyrtn8ocrjxyv3q7lslz; expires=Fri, 06-Jan-2017 07:18:45 GMT; httponly; Max-Age=600; Path=/
< 
* Closing connection 0
{"ok": true, "uuid": "f1852fcde4294f8c917522a12ec25fd1", "sign": "1tvksaww96ggfyrtn8ocrjxyv3q7lslz", "srvs": "127.0.0.1:1883", "expire": 600, "time": "1483686525"}

yjdwbj@mint17:~$ curl -v http://127.0.0.1:8000/iot/v1.0/app/auth/abc/123456/ -b "sessionid=1tvksaww96ggfyrtn8ocrjxyv3q7lslz; expires=Fri, 06-Jan-2017 07:18:45 GMT; httponly; Max-Age=600; Path=/"
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 127.0.0.1:8000
> Accept: */*
> Cookie: sessionid=1tvksaww96ggfyrtn8ocrjxyv3q7lslz; expires=Fri, 06-Jan-2017 07:18:45 GMT; httponly; Max-Age=600; Path=/
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Fri, 06 Jan 2017 07:09:11 GMT
< Server: WSGIServer/0.1 Python/2.7.10
< X-Frame-Options: SAMEORIGIN
< Content-Type: application/json; charset=utf-8
< 
* Closing connection 0
{"ok": true, "uuid": "f1852fcde4294f8c917522a12ec25fd1", "sign": "1tvksaww96ggfyrtn8ocrjxyv3q7lslz", "srvs": "127.0.0.1:1883", "expire": 600, "time": "1483686551"}

请教lor时的一个用户验证的方法

hi,请教一个问题。
我在验证用户的合法性之后,会生成一个token下发,服务端通过redis管理该token。
现在我需要所有的客户端请求过来,都验证一下token。
请问有没有办法在所有请求之前做一个判断呢?

return function(app)
app:get("/test1", function(req, res, next)
res:send("hello world")
end)
app:get("/test1", function(req, res, next)
res:send("hello world")
end)
end

如上述代码,我需要判断/signin之外的所有get请求的token,请问可有在每个get代码块里面去检查之外(重复代码很多,单独出来一个函数每次调用也不美观),可有更好的写法?

opm上更新版本

我想用opm方式安装lor, 但是现在还是0.3.1版本,麻烦更新一下版本,多谢大神!

lord 命令无效

mac 环境
首先resty和nginx命令都ok 然后sh install.sh 日志正常
但是 lord + 任何命令都无效 无论是 -h -v 还是 path

session.lua:108: func(): [session middleware]refresh cookie error

I didn't use OpenResty binary build directly. Instead, I compiled Nginx 1.13.0 independently. I then compiled and built luajit 2.0.5 with the following OpenResty components.
lua-cjson lua-resty-core lua-resty-logger-socket lua-resty-random lua-resty-session luasocket
lua-resty-cookie lua-resty-dns lua-resty-lrucache lua-resty-redis lua-resty-string

(I run VeryNginx, a WAF, with this configurations before. Things worked well.)

I configured cjson.so for Nginx with lua_package_cpath directive and configured lua_package_path directive to my own paths. I tried lor-example and was routed to the second page http://localhost:9999/auth/login. After using test/test to login, I got a "unknown" error message.

The log showed: (I modified the paths.)

2017/05/25 21:50:50 [error] 16079#16079: *2 [lua] session.lua:108: func(): [session middleware]refresh cookie error, stack traceback:
/path-to-lor/lor/lib/middleware/session.lua:104: in function </path-to-lor/lor/lib/middleware/session.lua:103>
[C]: in function 'require'
/path-to-luajit/lib/lua/resty/session.lua:34: in function 'prequire'
/path-to-luajit/lib/lua/resty/session.lua:214: in function 'new'
/path-to-luajit/lib/lua/resty/session.lua:257: in function 'open'
/path-to-luajit/lib/lua/resty/session.lua:320: in function 'start'
/path-to-lor/lor/lib/middleware/session.lua:69: in function 'update'
/path-to-lor/lor/lib/middleware/session.lua:101: in function </path-to-lor/lor/lib/middleware/session.lua:99>
[C]: in function 'xpcall'
/path-to-lor/lor/lib/middleware/session.lua:99: in function 'func'
/path-to-lor/lor/lib/router/router.lua:192: in function </path-to-lor/lor/lib/router/router.lua:191>
[C]: in function 'xpcall'
/path-to-lor/lor/lib/router/router.lua:191: in function 'next'
/path-to-lor/lor/lib/router/router.lua:213: in function 'handle'
/path-to-lor/lor/lib/application.lua:95: in function </path-to-lor/lor/lib/application.lua:94>
[C]: in function 'xpcall'
/path-to-lor/lor/lib/application.lua:94: in function 'handle'
/path-to-lor/lor/lib/application.lua:54: in function 'run'
...nload2017/lor/examples/lor-example-master/./app/main.lua:46: in function <...nload2017/lor/examples/lor-example-master/./app/main.lua:1>, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:9999"
2017/05/25 21:50:50 [error] 16079#16079: *2 [lua] check_login.lua:24: func(): -------->/ true, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:9999"
2017/05/25 21:50:58 [error] 16079#16079: *2 [lua] session.lua:108: func(): [session middleware]refresh cookie error, stack traceback:
/path-to-lor/lor/lib/middleware/session.lua:104: in function </path-to-lor/lor/lib/middleware/session.lua:103>
[C]: in function 'require'
/path-to-luajit/lib/lua/resty/session.lua:34: in function 'prequire'
/path-to-luajit/lib/lua/resty/session.lua:214: in function 'new'
/path-to-luajit/lib/lua/resty/session.lua:257: in function 'open'
/path-to-luajit/lib/lua/resty/session.lua:320: in function 'start'
/path-to-lor/lor/lib/middleware/session.lua:69: in function 'update'
/path-to-lor/lor/lib/middleware/session.lua:101: in function </path-to-lor/lor/lib/middleware/session.lua:99>
[C]: in function 'xpcall'
/path-to-lor/lor/lib/middleware/session.lua:99: in function 'func'
/path-to-lor/lor/lib/router/router.lua:192: in function </path-to-lor/lor/lib/router/router.lua:191>
[C]: in function 'xpcall'
/path-to-lor/lor/lib/router/router.lua:191: in function 'next'
/path-to-lor/lor/lib/router/router.lua:213: in function 'handle'
/path-to-lor/lor/lib/application.lua:95: in function </path-to-lor/lor/lib/application.lua:94>
[C]: in function 'xpcall'
/path-to-lor/lor/lib/application.lua:94: in function 'handle'
/path-to-lor/lor/lib/application.lua:54: in function 'run'
...nload2017/lor/examples/lor-example-master/./app/main.lua:46: in function <...nload2017/lor/examples/lor-example-master/./app/main.lua:1>, client: 127.0.0.1, server: , request: "GET /auth/login HTTP/1.1", host: "localhost:9999", referrer: "http://localhost:9999/"
2017/05/25 21:50:58 [error] 16079#16079: *2 [lua] check_login.lua:24: func(): -------->/auth/login true, client: 127.0.0.1, server: , request: "GET /auth/login HTTP/1.1", host: "localhost:9999", referrer: "http://localhost:9999/"

I couldn't figure out what went wrong. Please help. Thanks.

I want to got the method more than one choice.

some times we want to use the http-method router:get and router:post to adapt to our project,but lor can't able it.we should define a function first, then use router:get and router:post or all the http-method。could u create a new feature to resolve it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.