Skip to content
This repository

Simplified dependencies by using built-in modules #14

Merged
merged 5 commits into from over 2 years ago

2 participants

Justin Plock Neil Mansilla
Justin Plock

The querystring module is now included with Node (at least 0.6.7). I was also able to remove the dependency on hashlib by using the included crypto module.

Neil Mansilla
Owner

Accepting Justin's (jplock) pull request. Thanks for simplifying the dependencies. Just FYI, anyone following this, I'll be following up with Nathan's (nathanwdavis) pull request right after -- in particular, his changes to the package.json so that the simple "npm install" will be operational once again.

Neil Mansilla mansilladev merged commit ef0abc8 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 13 additions and 10 deletions. Show diff stats Hide diff stats

  1. +13 8 app.js
  2. +0 2  package.json
21 app.js
@@ -27,21 +27,20 @@
27 27 var express = require('express'),
28 28 util = require('util'),
29 29 fs = require('fs'),
30   - sys = require('sys'),
31 30 OAuth = require('oauth').OAuth,
32 31 query = require('querystring'),
33 32 url = require('url'),
34 33 http = require('http'),
  34 + crypto = require('crypto'),
35 35 redis = require('redis'),
36   - RedisStore = require('connect-redis')(express),
37   - hashlib = require('hashlib');
  36 + RedisStore = require('connect-redis')(express);
38 37
39 38 // Configuration
40 39 try {
41 40 var configJSON = fs.readFileSync(__dirname + "/config.json");
42 41 var config = JSON.parse(configJSON.toString());
43 42 } catch(e) {
44   - sys.puts("File config.json not found or is invalid. Try: `cp config.json.sample config.json`");
  43 + console.error("File config.json not found or is invalid. Try: `cp config.json.sample config.json`");
45 44 process.exit(1);
46 45 }
47 46
@@ -311,7 +310,7 @@ function processRequest(req, res, next) {
311 310 privateReqURL = apiConfig.protocol + '://' + apiConfig.baseURL + apiConfig.privatePath + methodURL + ((paramString.length > 0) ? '?' + paramString : ""),
312 311 options = {
313 312 headers: {},
314   - protocol: apiConfig.protocol,
  313 + protocol: apiConfig.protocol + ':',
315 314 host: baseHostUrl,
316 315 port: baseHostPort,
317 316 method: httpMethod,
@@ -470,7 +469,13 @@ function processRequest(req, res, next) {
470 469
471 470 // Add API Key to params, if any.
472 471 if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined) {
473   - options.path += '&' + apiConfig.keyParam + '=' + apiKey;
  472 + if (options.path.indexOf('?') !== -1) {
  473 + options.path += '&';
  474 + }
  475 + else {
  476 + options.path += '?';
  477 + }
  478 + options.path += apiConfig.keyParam + '=' + apiKey;
474 479 }
475 480
476 481 // Perform signature routine, if any.
@@ -478,13 +483,13 @@ function processRequest(req, res, next) {
478 483 if (apiConfig.signature.type == 'signed_md5') {
479 484 // Add signature parameter
480 485 var timeStamp = Math.round(new Date().getTime()/1000);
481   - var sig = hashlib.md5('' + apiKey + apiSecret + timeStamp + '', { asString: true });
  486 + var sig = crypto.createHash('md5').update('' + apiKey + apiSecret + timeStamp + '').digest('base64');
482 487 options.path += '&' + apiConfig.signature.sigParam + '=' + sig;
483 488 }
484 489 else if (apiConfig.signature.type == 'signed_sha256') { // sha256(key+secret+epoch)
485 490 // Add signature parameter
486 491 var timeStamp = Math.round(new Date().getTime()/1000);
487   - var sig = hashlib.sha256('' + apiKey + apiSecret + timeStamp + '', { asString: true });
  492 + var sig = crypto.createHash('sha256').update('' + apiKey + apiSecret + timeStamp + '').digest('base64');
488 493 options.path += '&' + apiConfig.signature.sigParam + '=' + sig;
489 494 }
490 495 }
2  package.json
@@ -23,10 +23,8 @@
23 23 "dependencies": {
24 24 "connect-redis": "1.0.6",
25 25 "express": "2.4.3",
26   - "hashlib": "1.0.1",
27 26 "jade": "0.13",
28 27 "oauth": "0.9.3",
29   - "querystring": "0.0.1",
30 28 "redis": "0.6.6"
31 29 },
32 30 "devDependencies": {},

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.