Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dkx/http-server

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dkx/http-server - npm Package Compare versions

Comparing version 0.1.6 to 1.0.0

lib/testing/index.d.ts

1

lib/index.d.ts

@@ -6,1 +6,2 @@ export { Middleware, NextMiddlewareFunction, RequestState } from './middleware';

export * from './request';
export * from './testing';

@@ -12,2 +12,3 @@ "use strict";

__export(require("./request"));
__export(require("./testing"));
//# sourceMappingURL=index.js.map

4

lib/response/response.d.ts

@@ -1,2 +0,2 @@

import { ResponseBodyBag, ResponseBodyBagAttachedListener } from './response-body-bag';
import { ResponseBodyBag } from './response-body-bag';
export declare type ResponseHeader = number | string | Array<string>;

@@ -18,3 +18,3 @@ export declare type ResponseHeaders = {

readonly headers: ResponseHeaders;
getBody(fn: ResponseBodyBagAttachedListener): void;
write(chunk: any): void;
withStatus(code: number, message?: string): Response;

@@ -21,0 +21,0 @@ hasHeader(name: string): boolean;

@@ -14,4 +14,4 @@ "use strict";

}
getBody(fn) {
this.bodyBag.onBodyAttached(fn);
write(chunk) {
this.bodyBag.onBodyAttached((body) => body.write(chunk));
}

@@ -18,0 +18,0 @@ withStatus(code, message = '') {

{
"name": "@dkx/http-server",
"version": "0.1.6",
"version": "1.0.0",
"description": "Minimalistic HTTP server",

@@ -5,0 +5,0 @@ "repository": "git@gitlab.com:dkx/http/server.git",

@@ -57,7 +57,5 @@ # DKX/Http/Server

{
response.getBody((body) => {
body.write('hello');
body.write(' ');
body.write('world');
});
response.write('hello');
response.write(' ');
response.write('world');

@@ -84,2 +82,37 @@ return next(response);

## Testing middlewares
Testing new middlewares is really easy with the built in helper function. It construct all the necessary objects and
runs the middleware for you.
```js
const {testMiddleware} = require('@dkx/http-server');
function myUselessMiddleware(request, response, next)
{
response = response.withHeader('X-Middleware-header', 'lorem ipsum');
return next(response);
}
const response = await testMiddleware(myUselessMiddleware, {
method: 'POST',
url: '/v1/users/5',
body: 'some HTTP body',
headers: {
'X-My-custom-http-header': 'hello world'
},
state: {
msg: 'My custom shared state'
}
});
console.log(response.getHeader('X-Middleware-header')); // output: "lorem ipsum"
```
The `testMiddleware` function can be used just with your middleware:
```js
testMiddleware(myUselessMiddleware);
```
## Server object

@@ -146,10 +179,10 @@

* **`getBody()`**
* **`write()`**
Method used for accessing the `ResponseBody` object, which can be used for writing the response data.
Method for writing data into response body.
**Arguments:**
`chunk: any`: data to write.
`fn: (body) => void`: callback with `ResponseBody` object.
* **`withStatus()`**

@@ -156,0 +189,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc