Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// all environments
app.set('ipaddr', settings.application.ip);
app.set('port', process.env.PORT || settings.application.port);
if (process.env.PORT) {
settings.application.port = process.env.PORT;
}
app.set('views', 'shared_views');
app.set('view engine', 'jade');
app.set('trust proxy', true);
app.enable("jsonp callback"); //TODO: Remove this if not needed because of CORS
app.use(express.favicon(path.join(__dirname, 'public/img/favicon.png')));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('eobfgl-shoe'));
app.use(express.session());
//Set up a public folder.
app.use(require('less-middleware')({
src: __dirname + '/public'
}));
//Items in these folders will be served statically.
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'GPModels')));
//support for storing authentication credentials
var passport = { authenticationFunctions: []};
//This must be after app.use(passport.initialize())
app.use(cors());
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('view options', {layout: false});
app.use(express.favicon())
app.use(express.cookieParser());
app.use(express.session({secret: settings.webserver.sessionKey}));
app.use(function(req, res, next) {
req.auth = {user: "webuser"};
// Used to implement authentication handled by a proxy upstream, by default assume "webuser" is always logged in.
/*
if (req.headers["x-authenticated-user"]) {
req.auth = {user: req.headers["x-authenticated-user"]};
}
*/
next();
});
// Force user to be logged-in for access
app.use(function(req, res, next) {
// Redirect user to proxy login page if not logged in
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({ store: sessionStore, secret: 'keyboard cat' }));
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(__dirname + '/../../public'));
});
var walk = require('walk');
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var _ = require('underscore');
// ------------------------------------------------
// BASIC USER AUTH w/ EXPRESS
// ------------------------------------------------
function authorize(user, pw) {
var userIsOk = false;
userIsOk |= (user === 'user' && pw === 'password');
return userIsOk;
}
var app = express.createServer();
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
secret: "a very secret secret",
store: new express.session.MemoryStore,
cookie: {
path : '/',
httpOnly : true,
maxAge : 1000*60*60*24*30*2 //60 days
}
}));
//app.use(express.basicAuth(authorize));
var uCount = (new Date()).getTime()%99999;
app.use(function(req, res, next){
req.user = req.user || {};
if(req.cookies && req.cookies["_username"]){
req.user.displayName = req.cookies["_username"];
}else{
req.user.displayName = "user_"+(uCount++);
var mongo = require('mongodb');
var async = require('async');
var express = require('express');
var passport = require('passport');
var app = express.createServer();
var sanitize = require('validator').sanitize;
var RSS = require('rss');
app.use(canonicalizeHost);
// Use the body parser express middleware to automatically parse
// POST form submissions
app.use(express.bodyParser());
// Make cookies available for sessions, which Passport requires to give us logins
app.use(express.cookieParser());
app.use(express.session({ secret: options.sessionSecret }));
// Now we can configure passport
configurePassport();
// Serve static files (such as CSS and js) in this folder
app.use('/static', express.static(__dirname + '/static'));
// Underscore templates to render various pages
options.templates.post = _.template(fs.readFileSync(__dirname + '/templates/post._', 'utf8'));
options.templates.postBody = _.template(fs.readFileSync(__dirname + '/templates/postBody._', 'utf8'));
options.templates.layout = _.template(fs.readFileSync(__dirname + '/templates/layout._', 'utf8'));
var db;
var postCollection;
async.series([connect, listen], ready);
var go = function() {
var app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride());
app.use(express.cookieParser());
var sessionStore = new express.session.MemoryStore();
app.use(express.session({ secret: 'windoge', store : sessionStore }));
// Set the x-powered-by header
app.use(function(req, res, next) {
res.header("X-powered-by", "Hobu, Inc.");
next();
});
app.use(require('less-middleware')(path.join(__dirname, 'public')));
app.use(express.static(__dirname + '/public'));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.use(app.router);
app.configure(function() {
app.use(express.cookieParser());
app.use(express.session({ secret : 'keima' }));
if(app.settings.env == 'development' || config.twitter.callback) {
app.use(auth([
auth.Twitter({consumerKey: config.twitter.consumerKey,
consumerSecret: config.twitter.consumerSecret,
callback : config.twitter.callback || 'http://localhost:3001/auth/twitter_callback' })]));
}else{
app.use(auth([
auth.Twitter({consumerKey: config.twitter.consumerKey,
consumerSecret: config.twitter.consumerSecret})]))
}
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
// helper
};
exports.watch = function(obj, cb) {
if(!watchers[obj.sid]) watchers[obj.sid] = {};
if(Object.keys(watchers[obj.sid]).length > 4)
return;
watchers[obj.sid][obj.cid] = cb;
console.log(watchers);
}
exports.unwatch = function(obj) {
if(watchers[obj.sid] && watchers[obj.sid][obj.cid])
delete watchers[obj.sid][obj.cid];
}
var exparse = express.session({
secret: secret,
key: key,
store: store
});
exports.store = store;
var parse = exports.parser = function(req, res, next) {
exparse(req, res, function() {
if(!req.session.user) {
req.session.user = initUser();
req.session.cookie.value = 's:' + signature.sign(req.sessionID, secret);
store.set(req.sessionID, req.session);
}
next();
});
function Configuration(app){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('view options',{layout:false});
app.use(express.bodyParser({uploadDir:rootdir+'/public/images/'}));
app.use(express.cookieParser());
app.use(express.session({secret:'keyboard cat',store:new RedisStore}));
app.use(express.methodOverride());
app.use(express['static'](__dirname + '/public'));
app.use(express.favicon(__dirname+'/public/favicon.ico'),{
maxAge:2592000000
});
app.use(app.router);
}
app.configure(function(){
app.use(express.cookieParser());
app.use(express.session({ 'key':'codematics',secret: "BSAIDG&*A^yuguisayds8a7" }));
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
app.use(setSession);
app.use(app.router);
});