net-util-base
v0.2.9
Published
set of utility modules for code traps to mongo db connection
Downloads
1
Readme
Description
Utility modules for different functions.
Code Block (block)
try catch code block so I don't have to put the same try catch all over the code.
Mongo DB connect (dbConnection)
connect to mongo db using environment variable process.env.DB_CONN
hits
This middle middle ware will look at each request that goes through the router looking for a match on from the "route" configuration. When an "req.originalUrl" path matches the "route" parameter, the domain and area are used to create a record in mongo db.
var hits = require("net-util-base").hits;
var hitList = [ { route: "/", domain: "readbible.us", area: "entry" } ];
appRouter.use(hits.create(hitList), express.static(__dirname + '/public_compiled'));
auth on google oAuth 2.0
Environment Variables
GOOGLE_CLIENT_ID=1234567890.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=secretfromgoogle
GOOGLE_REDIRECT=http://localhost/login/google/return
Code Sample
const appRouter = express();
const authRoute = require('./server/authRoute');
authRoute.initPassport(appRouter,
appPermissions.permissionCheck);
function permissionCheck(accessToken, refreshToken, profile, cb) {
let accessList = ['1123456789901234567890', '12345678901234567890'];
//put logic here for user access
const userHasAccess = accessList.indexOf(profile.id) > -1;
if (userHasAccess)
return cb(null, profile);
else
return cb(null, false, {message: 'User does not have access to this application'});
}