我在/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 }
许多不同的提供商都会复制它。任何想法如何在某种函数或数组中复制它,所以我不需要多次声明它?
答案 0 :(得分: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'
...