Comparing version 0.6.0 to 0.6.1
{ | ||
"name": "kequapp", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Non-intrusive Node JavaScript web app framework", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -245,3 +245,3 @@ <img alt="kequapp" src="https://github.com/Kequc/kequapp/blob/0.2-wip/logo.png?raw=true" width="142" height="85" /> | ||
Error handlers turn an exception into useful information that should be sent to the client. We may return a value to invoke a renderer or finalize the response ourselves directly. The default built-in error handler structures a json formatted response with helpful information for debugging. | ||
Error handlers turn an exception into useful information that should be sent to the client. The default built-in error handler structures a json formatted response with helpful information for debugging. | ||
@@ -259,3 +259,3 @@ The `'Content-Type'` header set by our application determines the correct error handler to use. Error handlers are sorted by the framework in favor of content type and hierarchical specificity. The following is a very simple error handler for text based responses. | ||
Errors thrown within an error handler or the renderer it invokes will cause a fatal exception and an empty `body` will be delivered to the client. | ||
This returns a string which will be passed to a renderer as the payload. Errors thrown within an error handler or the renderer it invokes will cause a fatal exception and an empty `body` will be delivered to the client. | ||
@@ -275,7 +275,7 @@ For a good example of how to write an error handler see this repo's [`/src/built-in`](https://github.com/Kequc/kequapp/tree/main/src/built-in) directory. | ||
An appropriate renderer is invoked whenever a handle returns a value apart from `undefined`. | ||
An appropriate renderer is invoked whenever a handle returns a value apart from `undefined`. We may return a value to invoke a renderer or finalize the response ourselves directly, which skips this step. | ||
Renderers are responsible for finalizing the response to the client. It is the last stage of a request and without one an empty `body` will be delivered. There are default renderers that come built-in for both `'text/*'` and `'application/json'`, however these can be overridden by defining our own. | ||
The `'Content-Type'` header set by our application determines the correct renderer to use. Error handlers are sorted by the framework in favor of content type and hierarchical specificity. The following is a simple example of what an html renderer might look like. | ||
The `'Content-Type'` header set by our application determines the correct renderer to use. Renderers are sorted by the framework in favor of content type and hierarchical specificity. The following is a simple example of what an html renderer might look like. | ||
@@ -290,4 +290,10 @@ ```javascript | ||
res.setHeader('Content-Length', Buffer.byteLength(json)); | ||
// finalize response | ||
res.end(html); | ||
if (req.method === 'HEAD') { | ||
res.end(); | ||
} else { | ||
res.end(html); | ||
} | ||
} | ||
@@ -501,2 +507,4 @@ }); | ||
The `raw` parameter is especially useful when our application expects a content type other than `'application/x-www-form-urlencoded'` or `'application/json'`. We receive a buffer which is most useful in order to process the request correctly. | ||
#### **`skipNormalize`** | ||
@@ -725,8 +733,8 @@ | ||
const setupAssets = createHandle(({ res, params }) => { | ||
if (params.wild === 'secret.txt') { | ||
const prepare = createHandle(({ res, params }) => { | ||
res.setHeader('Cache-Control', 'max-age=604800'); | ||
if (params.wild === '/secret.txt') { | ||
throw Ex.NotFound(); | ||
} | ||
res.setHeader('Cache-Control', 'max-age=604800'); | ||
}); | ||
@@ -739,3 +747,3 @@ | ||
url: '/assets/**', | ||
handles: [setupAssets, staticAssets] | ||
handles: [prepare, staticAssets] | ||
} | ||
@@ -742,0 +750,0 @@ ] |
117951
908