Skip to content

Commit

Permalink
new repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Royi Sitbon committed Jul 10, 2015
0 parents commit a577587
Show file tree
Hide file tree
Showing 1,662 changed files with 246,538 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
90 changes: 90 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var fs =require('fs');
//var mysql = require('mysql');
var pg = require('pg');
var app = express();
var server = require('http').createServer(app);

var engines = require('consolidate');
//app.engine('jade', engines.jade);
app.engine('html', engines.hogan);

// view engine setup
app.set('views', path.join(__dirname, 'views'));
//app.set('html', engines.hogan);
app.set('view engine', 'jade');

app.set('port', process.env.PORT || 7777);

//insert dataBase connection here

//connection.connect();
require('./utils/sqlConnection').setPostgresqlConnection(client);

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));

process.env.NODE_ENV = process.env.NODE_ENV || 'development';
//var config = require('./config/environment');
var routes = require('./routes/error');

//app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use(express.static(path.join(__dirname, 'public')));

// dynamically include routes (Controller)
fs.readdirSync(__dirname + '/routes').forEach(function (file) {
var route = '';
if (file.substr(-3) === '.js') {
route = require(__dirname + '/routes/' + file);
route.rootRoutes(app);
}
});


// catch 404 and forward to error handler
// app.use(function(req, res, next) {
// var err = new Error('Not Found');
// err.status = 404;
// next(err);
// });

// error handlers

// development error handler
// will print stacktrace
// if (app.get('env') === 'development') {
// app.use(function(err, req, res, next) {
// res.status(err.status || 500);
// res.render('error', {
// message: err.message,
// error: err
// });
// });
//}

// production error handler
// no stacktraces leaked to user
// app.use(function(err, req, res, next) {
// res.status(err.status || 500);
// res.render('error', {
// message: err.message,
// error: {}
// });
// });


app.listen(7777, function() {
console.log('Express server listening on port 7777');
});


module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('mongo-js:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
Binary file added config/.DS_Store
Binary file not shown.
Binary file added config/environment/.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions config/environment/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

// Development specific configuration
// ==================================

module.exports = {
// MongoDB connection options
mongo: {
uri: 'mongodb://localhost/test-dev'
},

mysql: {
//uri: 'mysql://root:pass@host/db?debug=true&charset=BIG5_CHINESE_CI&timezone=-0700'
uri: 'mysql://[email protected]/buysell?debug=true'
}

seedDB: true

};
31 changes: 31 additions & 0 deletions config/environment/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

// Production specific configuration
// =================================

module.exports = {
// Server IP
ip: process.env.OPENSHIFT_NODEJS_IP ||
process.env.IP ||
undefined,

// Server port
port: process.env.OPENSHIFT_NODEJS_PORT ||
process.env.PORT ||
8080,

// MongoDB connection options
mongo: {
uri: process.env.MONGOLAB_URI ||
process.env.MONGOHQ_URL ||
process.env.OPENSHIFT_MONGODB_DB_URL+process.env.OPENSHIFT_APP_NAME ||
'mongodb://localhost/test'
//'mongodb://<dbuser>:<dbpassword>@hostname:27017/<dbName>'
},

mysql: {
//uri: 'mysql://root:pass@host/db?debug=true&charset=BIG5_CHINESE_CI&timezone=-0700'
uri: 'mysql://root@host/buysell'
}

};
51 changes: 51 additions & 0 deletions config/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Express configuration
*/

'use strict';

var express = require('express');
var favicon = require('serve-favicon');
var morgan = require('morgan');
var compression = require('compression');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var cookieParser = require('cookie-parser');
var errorHandler = require('errorhandler');
var path = require('path');
var config = require('./environment');
var expressSession = require('express-session');
var passport = require('passport');

module.exports = function(app) {
var env = app.get('env');

app.set('views', config.root + '/server/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(compression());
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(methodOverride());
app.use(expressSession({secret: 'buy sell secret key'}));
app.use(passport.initialize());
app.use(passport.session());

if ('production' === env) {
app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
app.use(express.static(path.join(config.root, 'public')));
app.set('appPath', config.root + '/public');
app.use(morgan('dev'));
}

if ('development' === env || 'test' === env) {
app.use(require('connect-livereload')());
app.use(express.static(path.join(config.root, '.tmp')));
app.use(express.static(path.join(config.root, 'client')));
app.set('appPath', 'client');
app.use(morgan('dev'));
app.use(errorHandler()); // Error handler - has to be last
}
};
14 changes: 14 additions & 0 deletions config/local.env.sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

// Use local.env.js for environment variables that grunt will set when the server starts locally.
// Use for your api keys, secrets, etc. This file should not be tracked by git.
//
// You will need to set these on the server you deploy to.

module.exports = {
DOMAIN: 'http://localhost:9000',
SESSION_SECRET: 'test-secret',

// Control debug level for modules using visionmedia/debug
DEBUG: ''
};
40 changes: 40 additions & 0 deletions config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var mongoose = require('mongoose');
var User = require('../api/users/users.model');

// Configuring Passport

//using our own fields and not default username,password fields
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
},
function(email, password, done) {
User.findOne({email:email}).exec(function(err,user) {
console.log("user",user);
console.log("password",password);
if(user && user.authenticate(password)) {
return done(null, user);
} else {
return done(null,false);
}
});
}
));

passport.serializeUser(function(user,done) {
if(user) {
done(null,user._id);
}
});

passport.deserializeUser(function(id,done) {
User.findOne({_id:id}).exec(function(err,user) {
if(user) {
return done(null,user);
} else {
return done(null,false);
}
});
});
Loading

0 comments on commit a577587

Please sign in to comment.