0

我有这个咖啡脚本代码:

  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

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

任何建议都值得赞赏。

4

1 回答 1

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"]

查看循环的咖啡脚本文档

于 2013-07-04T14:31:36.687 回答