bun-router 0.2.1 → 0.2.2

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/examples/html.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { router, html } from '..';
1
+ import { router, file } from '..';
2
2
 
3
3
  Bun.serve
4
4
 
5
5
  const r = router(3000);
6
6
 
7
- r.add('/', 'GET', () => html('./examples/pages/index.html'));
7
+ r.add('/', 'GET', () => file('./examples/pages/index.html'));
8
8
 
9
9
  r.serve();
@@ -12,7 +12,7 @@ const notFound = async (): Promise<Response> => {
12
12
  });
13
13
  }
14
14
 
15
- const html = async (filepath: string): Promise<Response> => {
15
+ const file = async (filepath: string): Promise<Response> => {
16
16
  const file = Bun.file(filepath);
17
17
  const exists = await file.exists();
18
18
 
@@ -34,6 +34,18 @@ const html = async (filepath: string): Promise<Response> => {
34
34
  });
35
35
  }
36
36
 
37
+ const html = async (content: string): Promise<Response> => {
38
+ const response = new Response(content, {
39
+ status: 200,
40
+ statusText: 'ok',
41
+ headers: {'Content-Type': 'text/html'}
42
+ });
43
+
44
+ return new Promise<Response>((resolve) => {
45
+ resolve(response);
46
+ });
47
+ }
48
+
37
49
  const json = (data: any): Response => {
38
50
  const jsonString = JSON.stringify(data);
39
51
 
@@ -98,4 +110,4 @@ const router: Router = (port?: number | string, options?: Options) => {
98
110
  }
99
111
  }
100
112
 
101
- export { router, json, html, extractParams }
113
+ export { router, json, file, extractParams }
package/package.json CHANGED
@@ -8,5 +8,5 @@
8
8
  "peerDependencies": {
9
9
  "typescript": "^5.0.0"
10
10
  },
11
- "version": "0.2.1"
11
+ "version": "0.2.2"
12
12
  }
@@ -1,11 +1,11 @@
1
1
  import { describe, test, expect } from 'bun:test';
2
- import { html, json, extractParams } from '..';
2
+ import { file, json, extractParams } from '..';
3
3
  import { HttpRequest, Route } from '../lib/router/router.d';
4
4
 
5
5
  describe('Helpers', async () => {
6
6
  test('html', async () => {
7
7
  const fp = './examples/pages/index.html';
8
- const res = await html(fp);
8
+ const res = await file(fp);
9
9
  const contentType = res.headers.get('Content-Type');
10
10
 
11
11
  expect(contentType).toBe('text/html');