在快递申请中使用下划线

时间:2013-07-04 14:21:23

标签: javascript express coffeescript

我有这个咖啡脚本代码:

  dirs = ["/assets", "/public", "/locales", "/data/topo"]
  app.configure ->
      app.use assets(build : true)
      jsPaths assets, console.log
      @use(express.favicon(process.cwd() + "/assets/images/favicon.ico", {maxAge:maxAges}))
      .use(express.compress())
      .use(express.static(process.cwd() + "/assets", {maxAge:maxAges}))
      .use(express.static(process.cwd() + "/public", {maxAge:maxAges}))
      .use(express.static(process.cwd() + "/locales", {maxAge:maxAges}))
      .use(express.static(process.cwd() + "/data/topo", {maxAge:maxAges}))
      .use(express.logger('dev'))
      .use(express.errorHandler(
            dumpException: true
            showStack: true
      ))
  #  Add template engine

我想为所有dirs = ["/assets", "/public", "/locales", "/data/topo"]设置maxAge,这样做的正确方法是什么?

任何建议都值得赞赏。

1 个答案:

答案 0 :(得分:0)

为每个数组项调用一个方法?

setMaxAge folder for folder in ["/assets", "/public", "/locales", "/data/topo"]

setMaxAge(folder) ->
  app.use express.static( process.cwd() + folder, maxAge:maxAges )

或单行:

app.use express.static(process.cwd() + folder, maxAge:maxAges) for folder in ["/assets", "/public", "/locales", "/data/topo"]

查看coffeescript documentation for loops