hal-browser
Advanced tools
Comparing version 0.5.4 to 0.5.5
@@ -0,5 +1,11 @@ | ||
0.5.5 (2018-09-14) | ||
================== | ||
* Hidden feature: show full JSON bodies if `?_browser-fullbody` is in the url. | ||
0.5.4 (2018-09-06) | ||
================== | ||
* Don't throw erros on empty bodies. | ||
* Don't throw errors on empty bodies. | ||
@@ -6,0 +12,0 @@ |
@@ -1,1 +0,2 @@ | ||
export default function csvBody(body: any): Promise<string>; | ||
import { Context } from '@curveball/core'; | ||
export default function csvBody(ctx: Context): Promise<string>; |
@@ -10,6 +10,7 @@ "use strict"; | ||
const parse = util_1.promisify(csv_parse_1.default); | ||
async function csvBody(body) { | ||
async function csvBody(ctx) { | ||
let html = ` <h2>Contents</h2> | ||
<table class="body-csv"> | ||
`; | ||
const body = ctx.response.body; | ||
const data = await parse(body); | ||
@@ -16,0 +17,0 @@ let first = true; |
@@ -1,1 +0,2 @@ | ||
export default function halBody(body: any): string; | ||
import { Context } from '@curveball/core'; | ||
export default function halBody(ctx: Context): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("../util"); | ||
function halBody(body) { | ||
const tmpBody = Object.assign(body); | ||
delete tmpBody._links; | ||
delete tmpBody._embedded; | ||
function halBody(ctx) { | ||
const tmpBody = Object.assign(ctx.response.body); | ||
if (!('_browser-fullbody' in ctx.query)) { | ||
delete tmpBody._links; | ||
delete tmpBody._embedded; | ||
} | ||
const html = ` <h2>Contents</h2> | ||
@@ -9,0 +11,0 @@ <code class="hljs"><pre>${util_1.highlightJson(tmpBody)}</pre></code> |
@@ -1,1 +0,2 @@ | ||
export default function markdownBody(body: any): string; | ||
import { Context } from '@curveball/core'; | ||
export default function markdownBody(ctx: Context): string; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const markdown_it_1 = __importDefault(require("markdown-it")); | ||
function markdownBody(body) { | ||
function markdownBody(ctx) { | ||
let html = '<section class="body-markdown">'; | ||
@@ -20,3 +20,3 @@ html += markdown_it_1.default({ | ||
} | ||
}).render(body); | ||
}).render(ctx.response.body); | ||
html += '</section>'; | ||
@@ -23,0 +23,0 @@ return html; |
@@ -72,3 +72,3 @@ "use strict"; | ||
else { | ||
href = ctx.request.path; | ||
href = ctx.path; | ||
} | ||
@@ -101,7 +101,7 @@ const body = ctx.response.body; | ||
case 'application/hal+json': | ||
return hal_body_1.default(ctx.response.body); | ||
return hal_body_1.default(ctx); | ||
case 'text/markdown': | ||
return markdown_body_1.default(ctx.response.body); | ||
return markdown_body_1.default(ctx); | ||
case 'text/csv': | ||
return csv_body_1.default(ctx.response.body); | ||
return csv_body_1.default(ctx); | ||
default: | ||
@@ -108,0 +108,0 @@ return ''; |
@@ -84,11 +84,11 @@ "use strict"; | ||
return async (ctx, next) => { | ||
if (newOptions.serveAssets && ctx.request.path.startsWith('/_hal-browser/assets/')) { | ||
if (newOptions.serveAssets && ctx.path.startsWith('/_hal-browser/assets/')) { | ||
return serve_asset_1.default(ctx); | ||
} | ||
// Don't do anything if the raw format was requested | ||
if ('_browser-raw' in ctx.request.query) { | ||
if ('_browser-raw' in ctx.query) { | ||
return next(); | ||
} | ||
// Check to see if the client even wants html. | ||
if (!ctx.request.accepts('text/html')) { | ||
if (!ctx.accepts('text/html')) { | ||
return next(); | ||
@@ -106,3 +106,3 @@ } | ||
// This is useful if the client submitted a lower q= score for text/html | ||
if (ctx.request.accepts('text/html', ...exports.supportedContentTypes) === 'text/html') { | ||
if (ctx.accepts('text/html', ...exports.supportedContentTypes) === 'text/html') { | ||
await html_index_1.default(ctx, newOptions); | ||
@@ -109,0 +109,0 @@ } |
{ | ||
"name": "hal-browser", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "A HAL browser middleware", | ||
@@ -40,3 +40,3 @@ "main": "dist/index.js", | ||
"@types/highlight.js": "^9.12.3", | ||
"@types/markdown-it": "0.0.4", | ||
"@types/markdown-it": "0.0.5", | ||
"@types/mocha": "^5.2.5", | ||
@@ -49,3 +49,3 @@ "@types/node": "^10.9.4", | ||
"nyc": "^12.0.2", | ||
"sinon": "^6.2.0", | ||
"sinon": "^6.3.2", | ||
"ts-node": "^7.0.1", | ||
@@ -52,0 +52,0 @@ "tslint": "^5.11.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
69552
1216