Socket
Socket
Sign inDemoInstall

html2canvas-proxy

Package Overview
Dependencies
113
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 1.0.0

.travis.yml

0

examples/simple.js

@@ -0,0 +0,0 @@ var proxy = require("../server.js");

13

package.json
{
"name": "html2canvas-proxy",
"version": "0.0.5",
"version": "1.0.0",
"description": "Cross-origin content proxy for html2canvas",
"main": "server.js",
"scripts": {
"test": "mocha test"
"test": "exit 0"
},

@@ -24,7 +24,8 @@ "repository": {

"dependencies": {
"cors": "^2.4.2",
"express": "^4.9.3",
"qs": "^2.2.4",
"request": "^2.44.0"
"cors": "2.8.4",
"request": "2.81.0"
},
"peerDependencies": {
"express": "4.x"
}
}

@@ -1,36 +0,40 @@

var express = require('express');
var url = require('url');
var cors = require('cors');
var qs = require('qs');
var request = require('request');
const express = require('express');
const url = require('url');
const cors = require('cors');
const request = require('request');
module.exports = function() {
var app = express.Router();
function validUrl(req, res, next) {
req.query = req.query || qs.parse(url.parse(req.url).query);
if (req.query.url == null) {
next(new Error("No url specified"));
} else if (typeof(req.query.url) !== "string" || url.parse(req.query.url).host === null) {
next(new Error("Invalid url specified: " + req.query.url))
} else {
next();
}
function validUrl(req, res, next) {
if (!req.query.url) {
next(new Error('No url specified'));
} else if (typeof req.query.url !== 'string' || url.parse(req.query.url).host === null) {
next(new Error(`Invalid url specified: ${req.query.url}`));
} else {
next();
}
}
app.use(cors());
app.get('/', validUrl, function(req, res, next) {
if (typeof(req.query.callback) === "string") {
request({url: req.query.url, encoding: 'binary'}, function(error, response, body) {
if (error) {
return next(error);
}
res.jsonp({content: new Buffer(body, 'binary').toString('base64'), type: response.headers['content-type']});
});
} else {
req.pipe(request(req.query.url).on('error', next)).pipe(res);
}
module.exports = () => {
const app = express.Router();
app.get('/', cors(), validUrl, (req, res, next) => {
switch (req.query.responseType) {
case 'blob':
req.pipe(request(req.query.url).on('error', next)).pipe(res);
break;
case 'text':
default:
request({url: req.query.url, encoding: 'binary'}, (error, response, body) => {
if (error) {
return next(error);
}
res.send(
`data:${response.headers['content-type']};base64,${Buffer.from(
body,
'binary'
).toString('base64')}`
);
});
}
});
return app;
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc