Skip to content

Commit

Permalink
tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
RiteshKSingh1709 committed May 20, 2018
1 parent 104c35d commit 82b3bab
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 17 deletions.
12 changes: 12 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": 2
}
}
2 changes: 1 addition & 1 deletion nodeREST/.data/users/8276079012.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"firstName":"ritesh","lastName":"singh","phone":"8276079012","tosAgreement":true}
{"firstName":"ritesh","lastName":"singh","phone":"8276079012","password":"1c21e120fd019a533f8e108321d1e5d519050de8122d7d67666c7c76c6559dac","tosAgreement":true}
30 changes: 30 additions & 0 deletions nodeREST/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* configuration for envrionment specific
*
*/

var envrionments = {};

//envrionment specific to statgis
envrionments.staging = {
'httpPort' : 3000,
'httpsPort' : 3001,
'envName' : 'staging'
};

//envrionment specific to production
envrionments.production = {
'httpPort' : 5000,
'httpsPort' : 5001,
'envName' : 'production'
};

//get the current envrionment using command line argument
var currentEnvironment = typeof(process.env.NODE_ENV) == 'string' ? process.env.NODE_ENV.toLowerCase() : '';


//export the crrent environment from the above or default to staging
var currentEnvironmentToExport = typeof(envrionments[currentEnvironment]) == 'object' ? envrionments[currentEnvironment] : envrionments.staging;

//
module.exports = currentEnvironmentToExport;
13 changes: 7 additions & 6 deletions nodeREST/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ var DEBUG=true;
//Testing the create function
if(!DEBUG){
_data.create('test','newfile',{'foo':'bar'},'json',function(err){
console.log("The error is : "+ err)
console.log("The error is : "+ err);
});
}
//Testing the read function
if(DEBUG)
if(!DEBUG)
{
_data.read('test','newfile',function(err,data){
if(!err) {
Expand Down Expand Up @@ -90,7 +90,7 @@ var unifiedServer = function(req,res){
var trimmedUrl = path.replace(/^\/+|\/+$/g,'');
//get the queryString in the requested path
var queryStringObject = parsedUrl.query;
console.log(queryStringObject);
console.log("query string"+queryStringObject.phone);
//get the methd which that request came to the server
var method = req.method.toLowerCase();
//get the header as object
Expand Down Expand Up @@ -120,8 +120,8 @@ var unifiedServer = function(req,res){
'method' : method,
'headers' : header,
'payload' : helpers.parseJsonToObject(buffer),
}
console.log("The data is :"+data.payload.firstName + "The typeof : " + typeof(data.payload.firstName));
};
console.log("The data is :"+data.queryStringObject.phone + "The typeof : " + typeof(data.queryStringObject));
// for(let Obj in data.payload){
// console.log("coming here");
// console.log(Obj + " : " + data.payload[Obj] + "typeof(object) : " + typeof(data.payload[Obj]));
Expand All @@ -130,7 +130,7 @@ var unifiedServer = function(req,res){
choosenHandler(data,function(statusCode,payload){
//use the status code called by handler or deault
var statusCode = typeof(statusCode) =='number' ? statusCode : 404;

console.log("The payload is :"+typeof(payload)+''+payload);
//use the payload called by handler or default
var payload = typeof(payload) == 'object' ? payload : {};

Expand Down Expand Up @@ -162,3 +162,4 @@ var router = {};
router.sample = handlers.sample;
router.ping = handlers.ping;
router.users = handlers.users;
router.tokens = handlers.tokens;
4 changes: 2 additions & 2 deletions nodeREST/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ envrionments.staging = {
'httpsPort' : 3001,
'envName' : 'staging',
'hashingSecret' : 'thisIsSecret'
}
};

//envrionment specific to production
envrionments.production = {
'httpPort' : 5000,
'httpsPort' : 5001,
'envName' : 'production',
'hashingSecret' : 'thisIsAlsoSecret'
}
};

//get the current envrionment using command line argument
var currentEnvironment = typeof(process.env.NODE_ENV) == 'string' ? process.env.NODE_ENV.toLowerCase() : '';
Expand Down
25 changes: 22 additions & 3 deletions nodeREST/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//dependencies
var fs = require('fs');
var path = require('path');
var helpers = require('./helpers');

// container module to exported
var lib = {};
Expand Down Expand Up @@ -49,7 +50,14 @@ lib.create = function(dir,file,data,callback){
//Read data from file
lib.read = function(dir,file,callback){
fs.readFile(lib.baseDir+dir+'/'+file+'.json','utf-8',function(err,data){
callback(err,data);
if(!err && data) {
console.log("the data is " +data);
var parsedData = helpers.parseJsonToObject(JSON.stringify(data));
callback(err,JSON.parse(parsedData));
} else {
callback(err,data);
}

});
};

Expand All @@ -69,7 +77,7 @@ lib.update = function(dir,file,data,callback){
if(!err) {
fs.close(fileDescriptor,function(err){
if(!err) {
callback("false");
callback(false);
} else {
callback("Error in closing the existing file");
}
Expand All @@ -83,10 +91,21 @@ lib.update = function(dir,file,data,callback){
}
});
} else {

console.log("Unable to open the file");
}
});
};

//delete the data
lib.delete = function(dir,file,callback){
fs.unlink(lib.baseDir+dir+'/'+file+'.json',function(err){
if(!err) {
console.log("=========== In delete lib =============");
callback(false);
} else {
callback("Unable to delete the file");
}
});
};
//Export the module
module.exports = lib;
Loading

0 comments on commit 82b3bab

Please sign in to comment.