hyperdrive-http
Advanced tools
Comparing version 1.0.0 to 2.0.0
27
index.js
@@ -1,2 +0,1 @@ | ||
var http = require('http') | ||
var crypto = require('crypto') | ||
@@ -10,15 +9,6 @@ var pump = require('pump') | ||
var PORT = process.env.PORT || 8080 | ||
module.exports = HyperdriveHttp | ||
function HyperdriveHttp (getArchive, opts) { | ||
if (!opts) opts = {} | ||
opts.port = opts.port || PORT | ||
var server = this.server = http.createServer() | ||
server.listen(opts.port, function () { | ||
console.log('Server is listening on port ' + opts.port) | ||
}) | ||
server.on('request', function (req, res) { | ||
function HyperdriveHttp (getArchive) { | ||
var onrequest = function (req, res) { | ||
var dat = parse(req.url) | ||
@@ -30,11 +20,10 @@ if (!dat) return onerror(404, res) | ||
}) | ||
}) | ||
return server | ||
} | ||
return onrequest | ||
} | ||
function archiveResponse (archive, req, res) { | ||
if (!archive) { | ||
console.error('no archive') | ||
process.exit(0) | ||
} | ||
if (!archive) onerror(404, res) | ||
var dat = parse(req.url) | ||
@@ -94,2 +83,2 @@ | ||
} | ||
} | ||
} |
{ | ||
"name": "hyperdrive-http", | ||
"version": "1.0.0", | ||
"description": "serve a hyperdrive over http", | ||
"version": "2.0.0", | ||
"description": "Handle Hyperdrive HTTP Requests", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard && tape test/*.js | tap-spec" | ||
"test": "standard && echo 'Error: no test specified'" | ||
}, | ||
@@ -18,3 +18,11 @@ "author": "Joe Hand <joe@joeahand.com> (http://joeahand.com/)", | ||
"through-timeout": "^1.0.0" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/joehand/hyperdrive-http.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.comm/joehand/hyperdrive-http/issues" | ||
}, | ||
"homepage": "https://github.com/joehand/hyperdrive-http" | ||
} |
# Hyperdrive Http | ||
Serve a Hyperdrive over HTTP. | ||
Handle Hyperdrive HTTP Requests | ||
Expects you to: | ||
* Bring your own http server | ||
* Manage your own hyperdrive archives | ||
* Connect to the swarm before callback | ||
## Usage | ||
``` | ||
```javascript | ||
var hyperdriveHttp = require('hyperdrive-http') | ||
var opts = {port: 8000} | ||
var getArchive = function (datInfo, cb) { | ||
var archive = cache.get(dat.discoveryKey) | ||
// find the archive to serve | ||
var archive = cache.get(datInfo.discoveryKey) | ||
if (!archive) { | ||
archive = drive.createArchive(dat.key, {file: file}) | ||
archive = drive.createArchive(datInfo.key) | ||
// connect to swarm, if necessary | ||
sw.join(archive.discoveryKey) | ||
} | ||
cb(null, archive) // callback with your archive | ||
cb(null, archive) // callback with your found archive | ||
} | ||
var server = hyperdriveHttp(getArchive, opts) | ||
var onrequest = hyperdriveHttp(getArchive) | ||
var server = http.createServer() | ||
server.listen(8000) | ||
server.on('request', onrequest) | ||
``` | ||
@@ -25,3 +34,3 @@ | ||
``` | ||
```javascript | ||
datInfo = { | ||
@@ -28,0 +37,0 @@ key: archive.key, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
4896
40
0
0
67