0

我有这个:

./urls.coffee

urlConfig = [
    ["/", (req, res) -> res.send "hello world"]
]
module.exports = urlConfig

./utils/helpers.coffee

getUrl = (app, urlconfig)->
    for url in urlconfig
       app.get url[0], url[1]
module.exports.getUrl = getUrl    

./app.coffee

express = require "express",
app = express();
helper = require "./utils/helper"
urls = require "./urls"

helper.getUrl app, urls

我试图url通过app.coffee在另一个文件中定义它来区分url.coffee

但是回调不能接收(req, res)参数,错误是: req is not defined,但是如果回调没有接收到参数,它工作正常。有人有什么想法或建议吗?

4

1 回答 1

0

不应该是这样的:

var express = require "express",
helper = require "./utils/helper"

app = express();
app.get = helper.getUrl

?

于 2013-03-19T13:43:07.717 回答