node.js - Express: accessing app.set() settings in routes -



node.js - Express: accessing app.set() settings in routes -

in express, i'm led believe global app settings can created doing similar next in main app.js file:

var express = require('express'), ... login = require('./routes/login'); var app = express(); app.configure(function(){ ... app.set('ssohostname', 'login.hostname.com'); ... }); ... app.get('/login', login.login); ...

now in ./routes/login.js, i'd access app.settings.ssohostname, if effort run similar (as per: how access variables set using app.set() in express js):

... exports.login = function(req, res) { var currenturl = 'http://' + req.header('host') + req.url; if (!req.cookies.authcookie || !user.isvalidkey(req.cookies.authcookie)) { res.redirect(app.settings.ssohostname + '/login?returnurl=' + encodeuricomponent(currenturl)); } }; ...

it not recognize app:

referenceerror: app not defined

my questions are:

is approach took of using app.set() global settings re-used "proper" way , if so... how access these settings in routes? if not using app.set() global settings used often, how set , custom settings in routes?

at end of app.js file:

module.exports = app;

and in routes/login.js:

var app = require('../app');

now have access actual app object , won't referenceerror.

node.js express

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -