我需要在简单的 node.js 中等效于以下 express.js 代码,我可以在中间件中使用它。我需要根据 url 进行一些检查,并希望在自定义中间件中进行。
app.get "/api/users/:username", (req,res) ->
req.params.username
Run Code Online (Sandbox Code Playgroud)
到目前为止,我有以下代码,
app.use (req,res,next)->
if url.parse(req.url,true).pathname is '/api/users/:username' #this wont be true as in the link there will be a actual username not ":username"
#my custom check that I want to apply
Run Code Online (Sandbox Code Playgroud) 我有以下活跃的记录课
class Car < ActiveRecord::Base
belongs_to :owner
end
Run Code Online (Sandbox Code Playgroud)
在我尝试这个代码时
Car.first.owner
Run Code Online (Sandbox Code Playgroud)
它给我错误"未定义的方法所有者"
如果我遗漏任何东西,任何人都可以让我现在