@hono/node-server 0.4.0 → 0.5.0

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 CHANGED
@@ -77,7 +77,7 @@ app.get('/', (c) => c.json({ 'Hono meets': 'Node.js' }))
77
77
  serve(app)
78
78
  ```
79
79
 
80
- ### Serve Static Middleware
80
+ ## Serve Static Middleware
81
81
 
82
82
  Use Serve Static Middleware that has been created for Node.js.
83
83
 
@@ -89,7 +89,23 @@ import { serveStatic } from '@hono/node-server/serve-static'
89
89
  app.use('/static/*', serveStatic({ root: './' }))
90
90
  ```
91
91
 
92
- Note that `root` must be *relative* to the current working directory - absolute paths are not supported.
92
+ Note that `root` must be _relative_ to the current working directory - absolute paths are not supported.
93
+
94
+ ### Options
95
+
96
+ #### `rewriteRequestPath`
97
+
98
+ If you want to serve files in `./.foojs` with the request path `/__foo/*`, you can write like the following.
99
+
100
+ ```ts
101
+ app.use(
102
+ '/__foo/*',
103
+ serveStatic({
104
+ root: './.foojs/',
105
+ rewriteRequestPath: (path: string) => path.replace(/^\/__foo/, ''),
106
+ })
107
+ )
108
+ ```
93
109
 
94
110
  ## Related projects
95
111
 
package/dist/globals.js CHANGED
@@ -9,9 +9,12 @@ const web_stream_1 = require("@remix-run/web-stream");
9
9
  const base64_1 = require("./base64");
10
10
  const fetch_1 = require("./fetch");
11
11
  function installGlobals() {
12
- global.atob = base64_1.atob;
13
- global.btoa = base64_1.btoa;
14
- global.Blob = fetch_1.Blob;
12
+ if (typeof base64_1.atob === 'undefined')
13
+ global.atob = base64_1.atob;
14
+ if (typeof base64_1.btoa === 'undefined')
15
+ global.btoa = base64_1.btoa;
16
+ if (typeof Blob === 'undefined')
17
+ global.Blob = fetch_1.Blob;
15
18
  global.File = fetch_1.File;
16
19
  global.Headers = fetch_1.Headers;
17
20
  global.Request = fetch_1.Request;
@@ -20,8 +23,15 @@ function installGlobals() {
20
23
  global.FormData = fetch_1.FormData;
21
24
  global.ReadableStream = web_stream_1.ReadableStream;
22
25
  global.WritableStream = web_stream_1.WritableStream;
23
- if (typeof global.crypto === "undefined") {
24
- global.crypto = node_crypto_1.default;
26
+ if (typeof global.crypto === 'undefined') {
27
+ // If crypto.subtle is undefined, we're in a Node.js v16 environment
28
+ if (typeof node_crypto_1.default.subtle === 'undefined') {
29
+ // We can use the webcrypto polyfill
30
+ global.crypto = require('crypto').webcrypto;
31
+ }
32
+ else {
33
+ global.crypto = node_crypto_1.default;
34
+ }
25
35
  }
26
36
  }
27
37
  exports.installGlobals = installGlobals;
@@ -7,5 +7,6 @@ export declare type ServeStaticOptions = {
7
7
  root?: string;
8
8
  path?: string;
9
9
  index?: string;
10
+ rewriteRequestPath?: (path: string) => string;
10
11
  };
11
12
  export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<Response | undefined>;
@@ -11,8 +11,9 @@ const serveStatic = (options = { root: '' }) => {
11
11
  await next();
12
12
  }
13
13
  const url = new URL(c.req.url);
14
+ const filename = options.path ?? url.pathname;
14
15
  let path = (0, filepath_1.getFilePath)({
15
- filename: options.path ?? url.pathname,
16
+ filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
16
17
  root: options.root,
17
18
  defaultDocument: options.index ?? 'index.html',
18
19
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "HTTP Server for Hono on Node.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,7 +48,7 @@
48
48
  "@types/jest": "^29.0.1",
49
49
  "@types/node": "^18.7.16",
50
50
  "@types/supertest": "^2.0.12",
51
- "hono": "^2.7.1",
51
+ "hono": "^3.1.5",
52
52
  "jest": "^29.0.3",
53
53
  "next": "13.1.6",
54
54
  "np": "^7.6.2",