I'd like to configure different URLs for my production and dev environments that can be passed into my Jade templates. I have a couple links to subdomains, so I need the full URL. I don't want to hardcode the URL into the template. Can I pass the full url into the template and have the url specified in a configurable based on which environment the app is running in?
I have this in my app:
app.configure('production', function(){
});
app.configure('development', function(){
});
But I'm not sure what the contents of configure()
should be.
Once I have that configured, how can I access that from my routes file? Will those configurations be available to all files?
app.locals
lets you pass variables from your app to jade template. So you could do something like
app.configure('production', function(){
app.locals.URLs = {
resource1: '/production/resource1/url',
resource2: '/production/resource2/url',
}
});
app.configure('development', function(){
app.locals.URLs = {
resource1: '/development/resource1/url',
resource2: '/development/resource2/url',
}
});
And so you'll have access to the same variable which you can use in your template
script(src="#{URLs.resource1}")