I have this code in my /routes/index.coffee file:
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 }
It is replicated many times for many different providers. Any ideas how to replicate this in some sort of function or array so I don't need to declare it many times?
Configure it in your application setup.
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'
...