0

我的 /routes/index.coffee 文件中有这段代码:

exports.Dropbox = (req, res) ->
  production = if process.env['NODE_ENV'] == "production" then true
  if production
    mixpanelId = PROD_MIXPANEL_ID
  res.render 'connectors/Dropbox', { title: 'About Dropbox', mixpanelId: mixpanelId, production: production }

exports.Box = (req, res) ->
  production = if process.env['NODE_ENV'] == "production" then true
  if production
    mixpanelId = PROD_MIXPANEL_ID
  res.render 'connectors/Box', { title: 'About Box', mixpanelId: mixpanelId, production: production }

它被许多不同的提供者复制了很多次。任何想法如何在某种函数或数组中复制它,所以我不需要多次声明它?

4

1 回答 1

0

在您的应用程序设置中配置它。

app.configure 'production', ->
  app.set 'mixpanelId', PROD_MIXPANEL_ID

app.configure 'development', ->
  app.set 'mixpanelId', DEV_MIXPANEL_ID

// and in your handlers:
exports.Dropbox = (req, res) ->
  mixpanelId = req.app.get 'mixpanelId'
  ...
于 2013-06-06T05:22:50.337 回答