combo-url-parser
Advanced tools
Comparing version
var parser = require('./parser.js'); | ||
var request = require('request'); | ||
var CombinedStream = require('combined-stream'); | ||
var mime = require('mime'); | ||
/** | ||
* Middleware for connect | ||
* @param {Object} options | ||
* @param {Number} options.port | ||
* @returns {Function} | ||
*/ | ||
module.exports = function (options) { | ||
options = options || {}; | ||
if (!options.port) { | ||
throw new Error('combo-url-parser: port is missing!'); | ||
} | ||
var port = options.port; | ||
port = port ? ':' + port : ''; | ||
module.exports = function () { | ||
return function (req, res, next) { | ||
var urls = parser(req.url); | ||
@@ -28,5 +19,12 @@ | ||
// http://stackoverflow.com/questions/7109732/express-setting-content-type-based-on-path-file | ||
var type = mime.lookup(urls[0]); | ||
if (!res.getHeader('content-type')) { | ||
res.setHeader('Content-Type', type + '; charset=UTF-8'); | ||
} | ||
var combinedStream = CombinedStream.create(); | ||
urls.forEach(function (path) { | ||
combinedStream.append(request('http://127.0.0.1' + port + '/' + path)); | ||
combinedStream.append(request('http://' + req.headers.host + path)); | ||
combinedStream.append('\n'); | ||
@@ -33,0 +31,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"description": "A util to parser comboed url", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"repository": { | ||
@@ -19,3 +19,4 @@ "type": "git", | ||
"combined-stream": "0.0.4", | ||
"request": "~2.34.0" | ||
"request": "~2.34.0", | ||
"mime": "~1.2.11" | ||
}, | ||
@@ -22,0 +23,0 @@ "devDependencies": { |
@@ -27,2 +27,5 @@ [](http://travis-ci.org/maxbbn/combo-url-parser) | ||
### 0.1.2 | ||
- 添加 content-type Header | ||
### 0.1.1 | ||
@@ -29,0 +32,0 @@ |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
4311
2.25%33
10%0
-100%3
50%85
-2.3%+ Added