Skip to content

Commit

Permalink
1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CezaryDanielNowak committed Jan 9, 2023
1 parent 7499f9a commit a501863
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
example/
.git/
README.md
.editorconfig
.gitignore
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"license": "ISC",
"homepage": "https://github.com/CezaryDanielNowak/node-api-cache-proxy",
"dependencies": {
"express": "4.13.3",
"node-api-cache-proxy": "0.6.2",
"open": "0.0.5"
"express": "4.18.2",
"node-api-cache-proxy": "0.7.1",
"open": "8.4.0"
}
}
27 changes: 19 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@ var extract = require('url-querystring')
var filendir = require('filendir')
var fs = require('fs')
var getRawBody = require('raw-body')
var MD5 = require('crypto-js/md5');
var objectAssign = require('object-assign')
var omit = require('object.omit')
var packageJson = require('./package.json')
var path = require('path')
var request = require('request')
var sanitize = require('sanitize-filename')
var zlib = require('zlib')

var { createHash } = require('node:crypto');

/**
* Returns an MD5 hash for the given `content`.
*
* @param {String} content
* @returns {String}
*/
function MD5(content) {
return createHash('md5').update(content).digest('hex')
}

var MODULE_NAME = 'api-cache-proxy'

var log = console.log.bind(console, '[' + MODULE_NAME + '] ')
Expand All @@ -38,7 +48,7 @@ var defaultConfig = {
timeout: false
}

objectAssign(APICache.prototype, {
Object.assign(APICache.prototype, {
_createEnvelope: function(response, responseBody, requestBody) {
var excludeRequestHeaders = [
'content-encoding', // content is unpacked, content-encoding doesn't apply anymore,
Expand Down Expand Up @@ -225,7 +235,7 @@ function APICache(config) {
assert(config, 'APICache requres config provided')
assert(config.apiUrl, 'APICache: provide apiUrl')

this.config = objectAssign({}, defaultConfig, config)
this.config = Object.assign({}, defaultConfig, config)

var handleRequest = function(req, res) {
var url = this._getApiURL(req)
Expand All @@ -245,9 +255,6 @@ function APICache(config) {
})
.on('error', function(err) {
that.onError(apiReq, res, reqBodyRef.requestBody, resolve, reject)
promise.catch(function() {
log('API Error', url, err)
})
})
} else {
req.pipe(apiReq).pipe(res)
Expand All @@ -271,7 +278,11 @@ function APICache(config) {
return promise
}

return objectAssign(handleRequest.bind(this), this)
promise.catch(function() {
log('API Error', url, err)
})

return Object.assign(handleRequest.bind(this), this)
}

module.exports = APICache
Expand Down
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-api-cache-proxy",
"version": "0.6.4",
"version": "0.7.1",
"description": "Cache requests in nodejs",
"main": "index.js",
"scripts": {
Expand All @@ -17,14 +17,12 @@
},
"homepage": "https://github.com/CezaryDanielNowak/node-api-cache-proxy#readme",
"dependencies": {
"assert": "1.4.1",
"crypto-js": "3.1.9-1",
"filendir": "1.0.0",
"object-assign": "4.1.1",
"object.omit": "2.0.0",
"raw-body": "2.3.0",
"request": "2.81.0",
"sanitize-filename": "1.6.1",
"assert": "2.0.0",
"filendir": "2.0.1",
"object.omit": "3.0.0",
"raw-body": "2.5.1",
"request": "2.88.2",
"sanitize-filename": "1.6.3",
"url-querystring": "2.1.1"
}
}

0 comments on commit a501863

Please sign in to comment.