diff --git a/changelog.md b/changelog.md index d4cb994..cad96d1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,13 @@ Changelog ========= +1.0.3 (2024-01-15) +------------------ + +* Added a DOCTYPE so we're not in quircks mode. +* Added a bug related to loading image assets. + + 1.0.2 (2024-01-15) ------------------ diff --git a/package-lock.json b/package-lock.json index 5973198..cee3531 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@curveball/browser", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@curveball/browser", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "dependencies": { "@curveball/static": "^1", diff --git a/package.json b/package.json index c39afda..b8cf753 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curveball/browser", - "version": "1.0.2", + "version": "1.0.3", "description": "Automatic API browser generator. A middleware that turns your JSON responses into HTML if accessed by a browser.", "type": "module", "exports": "./dist/index.js", diff --git a/src/html-index.tsx b/src/html-index.tsx index a0ba4ec..aca74e1 100644 --- a/src/html-index.tsx +++ b/src/html-index.tsx @@ -41,7 +41,7 @@ export default async function generateHtmlIndex(ctx: Context, options: Options) } ctx.response.type = 'text/html; charset=utf-8'; - ctx.response.body = ReactDOMServer.renderToString( + ctx.response.body = '\n' + ReactDOMServer.renderToString( ): Middleware { const stat = staticMw({ - staticDir: __dirname + '/../assets', + staticDir: assetsPath, pathPrefix: '/_hal-browser/assets', maxAge: 3600, }); diff --git a/test/json-test.ts b/test/json-test.ts new file mode 100644 index 0000000..85b8981 --- /dev/null +++ b/test/json-test.ts @@ -0,0 +1,28 @@ +import { Application } from '@curveball/kernel'; +import browser from '../src/index.js'; +import { expect } from 'chai'; + +describe('Browser middleware integration test', () => { + + it('should render a HTML page when an `Accept` header with text/html is emitted', async() => { + + const app = new Application(); + const mw = browser(); + app.use(mw); + + app.use( ctx => { + ctx.response.body = { hello: 'world' }; + ctx.response.type = 'application/json'; + }); + + const resp = await app.subRequest('GET', '/', { + Accept: 'text/html' + }); + + expect(resp.status).to.equal(200); + expect(resp.is('html')).to.equal(true); + expect(resp.body).to.contain(''); + + }); + +}); diff --git a/test/test.ts b/test/test.ts deleted file mode 100644 index 7107a75..0000000 --- a/test/test.ts +++ /dev/null @@ -1,5 +0,0 @@ -describe('this package', () => { - it('should have tests', () => { - // Tests go here! - }); -});