我有这个:
./ 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)
args,错误是:
req is not defined
,但如果回调没有收到args,它可以正常工作。有人有任何想法或建议吗?
答案 0 :(得分:0)
不应该是这样的:
var express = require "express",
helper = require "./utils/helper"
app = express();
app.get = helper.getUrl