hyperdrive-http
Advanced tools
Comparing version 4.2.2 to 4.3.0
37
index.js
@@ -36,3 +36,3 @@ var toHTML = require('directory-index-html') | ||
archive.stat(name, function (err, st) { | ||
if (err) return onerror(res, 404, err) | ||
if (err) return on404(archive, res, req) | ||
@@ -62,2 +62,17 @@ if (st.isDirectory()) { | ||
function on404 (archive, req, res) { | ||
getManifest(archive, function (err, parsed) { | ||
if (err) return onerror(res, 404, err) | ||
var fallbackPage = parsed.fallback_page | ||
if (!fallbackPage) return onerror(res, 404, new Error('Not Found, No Fallback')) | ||
archive.stat(fallbackPage, function (err) { | ||
if (err) return onerror(res, 404, err) | ||
onfile(archive, fallbackPage, req, res) | ||
}) | ||
}) | ||
} | ||
function ondirectory (archive, name, req, res, opts) { | ||
@@ -96,3 +111,3 @@ archive.stat(name + 'index.html', function (err) { | ||
var footer = opts.footer ? opts.footer + ' Archive version: ' + archive.version : null | ||
var footer = opts.footer ? 'Archive version: ' + archive.version : null | ||
var html = toHTML({directory: name, script: (!opts.live || archive._checkout) ? null : script, footer: footer}, entries) | ||
@@ -110,2 +125,19 @@ res.setHeader('Content-Type', 'text/html; charset=utf-8') | ||
function getManifest (archive, cb) { | ||
archive.readFile('/dat.json', 'utf-8', function (err, data) { | ||
if (err) cb(err) | ||
try { | ||
var parsed = JSON.parse(data) | ||
} catch (e) { | ||
return cb(err) | ||
} | ||
if (!parsed || Array.isArray(parsed) || (typeof parsed !== 'object')) { | ||
return cb(new Error('Invalid dat.json format')) | ||
} | ||
cb(null, parsed) | ||
}) | ||
} | ||
function waitFor (archive, until, cb) { // this feels a bit hacky, TODO: make less complicated? | ||
@@ -121,2 +153,3 @@ archive.setMaxListeners(0) | ||
res.statusCode = status | ||
res.setHeader('Content-Type', 'text/plain; charset=utf-8') | ||
res.end(err.stack) | ||
@@ -123,0 +156,0 @@ } |
{ | ||
"name": "hyperdrive-http", | ||
"version": "4.2.2", | ||
"version": "4.3.0", | ||
"description": "Handle Hyper[drive|core] HTTP Requests", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
21911
11
569
3
6