@kiyasov/platform-hono 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +80 -24
- package/benchmarks/benchmark.mjs +12 -12
- package/dist/cjs/src/multer/storage/memory-storage.d.ts +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/multer/storage/memory-storage.d.ts +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +21 -24
package/Readme.md
CHANGED
|
@@ -3,38 +3,49 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@kiyasov/platform-hono)
|
|
4
4
|
[](https://www.npmjs.com/package/@kiyasov/platform-hono)
|
|
5
5
|
|
|
6
|
-
This package allows you to use Hono with
|
|
6
|
+
This package allows you to use [Hono](https://hono.dev/) with [NestJS](https://nestjs.com/).
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Installation
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
```bash
|
|
11
|
+
# npm
|
|
12
|
+
npm install @kiyasov/platform-hono
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add @kiyasov/platform-hono
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
# pnpm
|
|
18
|
+
pnpm add @kiyasov/platform-hono
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# or
|
|
21
|
-
yarn add @kiyasov/platform-hono
|
|
20
|
+
# bun
|
|
21
|
+
bun add @kiyasov/platform-hono
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### Basic Setup
|
|
25
27
|
|
|
26
28
|
```typescript
|
|
27
|
-
import { NestFactory } from
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
29
|
+
import { NestFactory } from '@nestjs/core';
|
|
30
|
+
import { HonoAdapter } from '@kiyasov/platform-hono';
|
|
31
|
+
import { AppModule } from './app.module';
|
|
32
|
+
|
|
33
|
+
async function bootstrap() {
|
|
34
|
+
const app = await NestFactory.create(
|
|
35
|
+
AppModule,
|
|
36
|
+
new HonoAdapter()
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
await app.listen(3000);
|
|
40
|
+
console.log(`Application is running on: ${await app.getUrl()}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
bootstrap();
|
|
35
44
|
```
|
|
36
45
|
|
|
37
|
-
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
### Exception Filter with HonoAdapter
|
|
38
49
|
|
|
39
50
|
```typescript
|
|
40
51
|
import {
|
|
@@ -43,8 +54,8 @@ import {
|
|
|
43
54
|
ArgumentsHost,
|
|
44
55
|
HttpException,
|
|
45
56
|
HttpStatus,
|
|
46
|
-
} from
|
|
47
|
-
import { HttpAdapterHost } from
|
|
57
|
+
} from '@nestjs/common';
|
|
58
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
48
59
|
|
|
49
60
|
@Catch()
|
|
50
61
|
export class AllExceptionsFilter implements ExceptionFilter {
|
|
@@ -52,7 +63,6 @@ export class AllExceptionsFilter implements ExceptionFilter {
|
|
|
52
63
|
|
|
53
64
|
catch(exception: unknown, host: ArgumentsHost): void {
|
|
54
65
|
const { httpAdapter } = this.httpAdapterHost;
|
|
55
|
-
|
|
56
66
|
const ctx = host.switchToHttp();
|
|
57
67
|
|
|
58
68
|
const httpStatus =
|
|
@@ -70,3 +80,49 @@ export class AllExceptionsFilter implements ExceptionFilter {
|
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Advanced Configuration
|
|
86
|
+
|
|
87
|
+
### Custom Hono Instance
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { Hono } from 'hono';
|
|
91
|
+
import { cors } from 'hono/cors';
|
|
92
|
+
import { logger } from 'hono/logger';
|
|
93
|
+
|
|
94
|
+
async function bootstrap() {
|
|
95
|
+
const honoApp = new Hono();
|
|
96
|
+
|
|
97
|
+
// Add Hono middleware
|
|
98
|
+
honoApp.use('*', cors());
|
|
99
|
+
honoApp.use('*', logger());
|
|
100
|
+
|
|
101
|
+
const app = await NestFactory.create(
|
|
102
|
+
AppModule,
|
|
103
|
+
new HonoAdapter(honoApp)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
await app.listen(3000);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## Contributing
|
|
114
|
+
|
|
115
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
|
120
|
+
|
|
121
|
+
## Support
|
|
122
|
+
|
|
123
|
+
For issues and questions, please use the [GitHub issue tracker](https://github.com/kiyasov/platform-hono/issues).
|
|
124
|
+
|
|
125
|
+
## Acknowledgments
|
|
126
|
+
|
|
127
|
+
- [Hono](https://hono.dev/) - The ultrafast web framework
|
|
128
|
+
- [NestJS](https://nestjs.com/) - A progressive Node.js framework
|
package/benchmarks/benchmark.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import autocannon from
|
|
2
|
-
import { PassThrough } from
|
|
1
|
+
import autocannon from 'autocannon';
|
|
2
|
+
import { PassThrough } from 'stream';
|
|
3
3
|
|
|
4
4
|
// Example base64-encoded image (black square 100x100 pixels)
|
|
5
5
|
const base64Content =
|
|
6
|
-
|
|
6
|
+
'iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAABmJLR0QA/wD/AP+gvaeTAAAAJ0lEQVR4nO3BAQEAAACCIP+vbkhAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwH8GAAF3Xq9HAAAAAElFTkSuQmCC';
|
|
7
7
|
|
|
8
8
|
// Create the request body with the base64 string
|
|
9
9
|
const formData = `--boundary
|
|
@@ -15,8 +15,8 @@ ${base64Content}
|
|
|
15
15
|
|
|
16
16
|
// Set up headers
|
|
17
17
|
const headers = {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
'Content-Type': 'multipart/form-data; boundary=boundary',
|
|
19
|
+
'Content-Length': Buffer.byteLength(formData),
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const pass = new PassThrough();
|
|
@@ -24,12 +24,12 @@ pass.end(formData);
|
|
|
24
24
|
|
|
25
25
|
const chunks = [];
|
|
26
26
|
|
|
27
|
-
pass.on(
|
|
28
|
-
pass.on(
|
|
27
|
+
pass.on('data', (chunk) => chunks.push(chunk));
|
|
28
|
+
pass.on('end', () => {
|
|
29
29
|
const formBuffer = Buffer.concat(chunks);
|
|
30
30
|
const instance = autocannon({
|
|
31
|
-
url:
|
|
32
|
-
method:
|
|
31
|
+
url: 'http://localhost:3000/uploadFile',
|
|
32
|
+
method: 'POST',
|
|
33
33
|
headers: headers,
|
|
34
34
|
body: formBuffer,
|
|
35
35
|
connections: 200,
|
|
@@ -39,13 +39,13 @@ pass.on("end", () => {
|
|
|
39
39
|
|
|
40
40
|
autocannon.track(instance, { renderProgressBar: true });
|
|
41
41
|
|
|
42
|
-
process.once(
|
|
42
|
+
process.once('SIGINT', () => {
|
|
43
43
|
instance.stop();
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
pass.on(
|
|
48
|
-
console.error(
|
|
47
|
+
pass.on('error', (err) => {
|
|
48
|
+
console.error('Error reading data from the stream', err);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
pass.resume();
|
|
@@ -12,7 +12,7 @@ export declare class MemoryStorage implements Storage<MemoryStorageFile> {
|
|
|
12
12
|
mimetype: string;
|
|
13
13
|
fieldname: string;
|
|
14
14
|
originalFilename: string;
|
|
15
|
-
stream: () => ReadableStream<Uint8Array<
|
|
15
|
+
stream: () => ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
16
16
|
lastModified: number;
|
|
17
17
|
}>;
|
|
18
18
|
removeFile(file: MemoryStorageFile): Promise<void>;
|