Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(readme): improve documentation #168

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/whook-http-router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ async function initHTTPRouter<T extends WhookHandler>({

if (castedResponse.body && 'head' === request.method) {
log(
'warning',
'Body stripped:',
'debug',
'💇 - Body stripped:',
castedResponse.body instanceof Stream
? 'Stream'
: castedResponse.body,
Expand Down Expand Up @@ -545,7 +545,10 @@ async function initHTTPRouter<T extends WhookHandler>({
}
}

function _explodePath(path, parameters) {
function _explodePath(
path: string,
parameters: DereferencedParameterObject[],
): (string | DereferencedParameterObject)[] {
return path
.split(PATH_SEPARATOR)
.filter(identity)
Expand Down Expand Up @@ -631,7 +634,10 @@ async function _createRouters<T extends WhookHandler>({

routers[method] = routers[method] || new Siso();
routers[method].register(
_explodePath(BASE_PATH + path, pathParameters),
_explodePath(
BASE_PATH + path,
pathParameters as unknown[] as DereferencedParameterObject[],
),
_prepareRoute({ ajv }, operation, handler, ammendedParameters),
);
});
Expand Down
19 changes: 12 additions & 7 deletions packages/whook-http-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@

[//]: # (::contents:start)

The [Whook](https://github.com/nfroidure/whook)'s `httpServer` service
is responsible for instanciating the NodeJS HTTP Server and handling
its start/shutdown.

It can be easily replaced by any other HTTP server (an HTTPS one for
instance if you cannot use a gateway or a proxy to handle HTTPS
connections).
The [Whook](https://github.com/nfroidure/whook)'s `httpServer` service is
responsible for instanciating the NodeJS HTTP Server and handling its
start/shutdown.

It can be easily replaced by any other HTTP server (an HTTPS one for instance if
you cannot use a gateway or a proxy to handle HTTPS connections).

The server takes in charge graceful shutdown by awaiting connections to be
closed before shutting down which can take a long time (basically if a browser
is still maintaining an open socket with it). You can short circuit this
behavior, basically for development, by setting the `DESTROY_SOCKETS=1`
environment variable.

[//]: # (::contents:end)

Expand Down
27 changes: 15 additions & 12 deletions packages/whook-http-transaction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@

[//]: # (::contents:start)

[Whook](https://github.com/nfroidure/whook) takes a very unusual direction
when it comes to dealing with HTTP transactions. It makes requests and
responses serializable to:
- only work with functions that take request and return responses (
allowing your handlers to be pure functions),
- have [easily unit testable](https://github.com/nfroidure/whook/blob/e7470fed860a8e1644b15625c9db4dd8198b70a6/packages/whook-example/src/handlers/putEcho.test.js)
handlers thanks to concise snapshots.

This service is intended to build those objects from Node HTTP ones
before passing them to the handlers. It also keeps track of running
queries and ensure it is well handled by the server before releasing
it.
[Whook](https://github.com/nfroidure/whook) takes a very unusual direction when
it comes to dealing with HTTP transactions. It makes requests and responses
serializable (thanks to `WhookRequest` and `WhookResponse` types) to:

- only work with functions that take request and return responses ( allowing
your handlers to be pure functions),
- have
[easily unit testable](https://github.com/nfroidure/whook/blob/e7470fed860a8e1644b15625c9db4dd8198b70a6/packages/whook-example/src/handlers/putEcho.test.js)
handlers thanks to concise snapshots.

This service is intended to build those litteral objects from Node HTTP ones
(famously known as req/res) before passing them to the handlers. It also keeps
track of running queries and ensure it is well handled by the server before
releasing it. If not, the transaction is resolved with an error response (for
timeouts or when an error were catched).

[//]: # (::contents:end)

Expand Down