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

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

Open
sumory opened this Issue Feb 15, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@sumory
Owner

sumory commented Feb 15, 2017

假设我们有一个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)

@sumory sumory added the question label Feb 17, 2017

@sumory sumory added docs and removed question labels Mar 1, 2017

@sumory

This comment has been minimized.

Show comment
Hide comment
@sumory

sumory Apr 16, 2017

Owner

done with commit #d47632

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

-- also support multi middlewares
user_router:get(function(req, res, next) 
    req.params.test_var = 1
end, function(req, res, next) 
    req.params.test_var = 2
end, function(req, res, next)
    res:send("now the test_var is " .. req.params.test_var) -- 2
end)
Owner

sumory commented Apr 16, 2017

done with commit #d47632

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

-- also support multi middlewares
user_router:get(function(req, res, next) 
    req.params.test_var = 1
end, function(req, res, next) 
    req.params.test_var = 2
end, function(req, res, next)
    res:send("now the test_var is " .. req.params.test_var) -- 2
end)
@coderlikeadog

This comment has been minimized.

Show comment
Hide comment
@coderlikeadog

coderlikeadog commented Nov 22, 2017

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment