@hono/node-server 1.11.4 → 1.11.5
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/dist/serve-static.js +4 -96
- package/dist/serve-static.mjs +2 -94
- package/package.json +3 -3
package/dist/serve-static.js
CHANGED
|
@@ -24,100 +24,8 @@ __export(serve_static_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(serve_static_exports);
|
|
26
26
|
var import_fs = require("fs");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var getFilePath = (options) => {
|
|
30
|
-
let filename = options.filename;
|
|
31
|
-
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
let root = options.root || "";
|
|
35
|
-
const defaultDocument = options.defaultDocument || "index.html";
|
|
36
|
-
if (filename.endsWith("/")) {
|
|
37
|
-
filename = filename.concat(defaultDocument);
|
|
38
|
-
} else if (!filename.match(/\.[a-zA-Z0-9]+$/)) {
|
|
39
|
-
filename = filename.concat("/" + defaultDocument);
|
|
40
|
-
}
|
|
41
|
-
filename = filename.replace(/^\.?[\/\\]/, "");
|
|
42
|
-
filename = filename.replace(/\\/, "/");
|
|
43
|
-
root = root.replace(/\/$/, "");
|
|
44
|
-
let path = root ? root + "/" + filename : filename;
|
|
45
|
-
path = path.replace(/^\.?\//, "");
|
|
46
|
-
return path;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// node_modules/hono/dist/utils/mime.js
|
|
50
|
-
var getMimeType = (filename, mimes = baseMimes) => {
|
|
51
|
-
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
52
|
-
const match = filename.match(regexp);
|
|
53
|
-
if (!match) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let mimeType = mimes[match[1]];
|
|
57
|
-
if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
|
|
58
|
-
mimeType += "; charset=utf-8";
|
|
59
|
-
}
|
|
60
|
-
return mimeType;
|
|
61
|
-
};
|
|
62
|
-
var baseMimes = {
|
|
63
|
-
aac: "audio/aac",
|
|
64
|
-
avi: "video/x-msvideo",
|
|
65
|
-
avif: "image/avif",
|
|
66
|
-
av1: "video/av1",
|
|
67
|
-
bin: "application/octet-stream",
|
|
68
|
-
bmp: "image/bmp",
|
|
69
|
-
css: "text/css",
|
|
70
|
-
csv: "text/csv",
|
|
71
|
-
eot: "application/vnd.ms-fontobject",
|
|
72
|
-
epub: "application/epub+zip",
|
|
73
|
-
gif: "image/gif",
|
|
74
|
-
gz: "application/gzip",
|
|
75
|
-
htm: "text/html",
|
|
76
|
-
html: "text/html",
|
|
77
|
-
ico: "image/x-icon",
|
|
78
|
-
ics: "text/calendar",
|
|
79
|
-
jpeg: "image/jpeg",
|
|
80
|
-
jpg: "image/jpeg",
|
|
81
|
-
js: "text/javascript",
|
|
82
|
-
json: "application/json",
|
|
83
|
-
jsonld: "application/ld+json",
|
|
84
|
-
map: "application/json",
|
|
85
|
-
mid: "audio/x-midi",
|
|
86
|
-
midi: "audio/x-midi",
|
|
87
|
-
mjs: "text/javascript",
|
|
88
|
-
mp3: "audio/mpeg",
|
|
89
|
-
mp4: "video/mp4",
|
|
90
|
-
mpeg: "video/mpeg",
|
|
91
|
-
oga: "audio/ogg",
|
|
92
|
-
ogv: "video/ogg",
|
|
93
|
-
ogx: "application/ogg",
|
|
94
|
-
opus: "audio/opus",
|
|
95
|
-
otf: "font/otf",
|
|
96
|
-
pdf: "application/pdf",
|
|
97
|
-
png: "image/png",
|
|
98
|
-
rtf: "application/rtf",
|
|
99
|
-
svg: "image/svg+xml",
|
|
100
|
-
tif: "image/tiff",
|
|
101
|
-
tiff: "image/tiff",
|
|
102
|
-
ts: "video/mp2t",
|
|
103
|
-
ttf: "font/ttf",
|
|
104
|
-
txt: "text/plain",
|
|
105
|
-
wasm: "application/wasm",
|
|
106
|
-
webm: "video/webm",
|
|
107
|
-
weba: "audio/webm",
|
|
108
|
-
webp: "image/webp",
|
|
109
|
-
woff: "font/woff",
|
|
110
|
-
woff2: "font/woff2",
|
|
111
|
-
xhtml: "application/xhtml+xml",
|
|
112
|
-
xml: "application/xml",
|
|
113
|
-
zip: "application/zip",
|
|
114
|
-
"3gp": "video/3gpp",
|
|
115
|
-
"3g2": "video/3gpp2",
|
|
116
|
-
gltf: "model/gltf+json",
|
|
117
|
-
glb: "model/gltf-binary"
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// src/serve-static.ts
|
|
27
|
+
var import_filepath = require("hono/utils/filepath");
|
|
28
|
+
var import_mime = require("hono/utils/mime");
|
|
121
29
|
var createStreamBody = (stream) => {
|
|
122
30
|
const body = new ReadableStream({
|
|
123
31
|
start(controller) {
|
|
@@ -140,7 +48,7 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
140
48
|
return next();
|
|
141
49
|
}
|
|
142
50
|
const filename = options.path ?? decodeURIComponent(c.req.path);
|
|
143
|
-
let path = getFilePath({
|
|
51
|
+
let path = (0, import_filepath.getFilePath)({
|
|
144
52
|
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
|
|
145
53
|
root: options.root,
|
|
146
54
|
defaultDocument: options.index ?? "index.html"
|
|
@@ -153,7 +61,7 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
153
61
|
await options.onNotFound?.(path, c);
|
|
154
62
|
return next();
|
|
155
63
|
}
|
|
156
|
-
const mimeType = getMimeType(path);
|
|
64
|
+
const mimeType = (0, import_mime.getMimeType)(path);
|
|
157
65
|
if (mimeType) {
|
|
158
66
|
c.header("Content-Type", mimeType);
|
|
159
67
|
}
|
package/dist/serve-static.mjs
CHANGED
|
@@ -1,99 +1,7 @@
|
|
|
1
1
|
// src/serve-static.ts
|
|
2
2
|
import { createReadStream, existsSync, lstatSync } from "fs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var getFilePath = (options) => {
|
|
6
|
-
let filename = options.filename;
|
|
7
|
-
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
let root = options.root || "";
|
|
11
|
-
const defaultDocument = options.defaultDocument || "index.html";
|
|
12
|
-
if (filename.endsWith("/")) {
|
|
13
|
-
filename = filename.concat(defaultDocument);
|
|
14
|
-
} else if (!filename.match(/\.[a-zA-Z0-9]+$/)) {
|
|
15
|
-
filename = filename.concat("/" + defaultDocument);
|
|
16
|
-
}
|
|
17
|
-
filename = filename.replace(/^\.?[\/\\]/, "");
|
|
18
|
-
filename = filename.replace(/\\/, "/");
|
|
19
|
-
root = root.replace(/\/$/, "");
|
|
20
|
-
let path = root ? root + "/" + filename : filename;
|
|
21
|
-
path = path.replace(/^\.?\//, "");
|
|
22
|
-
return path;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// node_modules/hono/dist/utils/mime.js
|
|
26
|
-
var getMimeType = (filename, mimes = baseMimes) => {
|
|
27
|
-
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
28
|
-
const match = filename.match(regexp);
|
|
29
|
-
if (!match) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
let mimeType = mimes[match[1]];
|
|
33
|
-
if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
|
|
34
|
-
mimeType += "; charset=utf-8";
|
|
35
|
-
}
|
|
36
|
-
return mimeType;
|
|
37
|
-
};
|
|
38
|
-
var baseMimes = {
|
|
39
|
-
aac: "audio/aac",
|
|
40
|
-
avi: "video/x-msvideo",
|
|
41
|
-
avif: "image/avif",
|
|
42
|
-
av1: "video/av1",
|
|
43
|
-
bin: "application/octet-stream",
|
|
44
|
-
bmp: "image/bmp",
|
|
45
|
-
css: "text/css",
|
|
46
|
-
csv: "text/csv",
|
|
47
|
-
eot: "application/vnd.ms-fontobject",
|
|
48
|
-
epub: "application/epub+zip",
|
|
49
|
-
gif: "image/gif",
|
|
50
|
-
gz: "application/gzip",
|
|
51
|
-
htm: "text/html",
|
|
52
|
-
html: "text/html",
|
|
53
|
-
ico: "image/x-icon",
|
|
54
|
-
ics: "text/calendar",
|
|
55
|
-
jpeg: "image/jpeg",
|
|
56
|
-
jpg: "image/jpeg",
|
|
57
|
-
js: "text/javascript",
|
|
58
|
-
json: "application/json",
|
|
59
|
-
jsonld: "application/ld+json",
|
|
60
|
-
map: "application/json",
|
|
61
|
-
mid: "audio/x-midi",
|
|
62
|
-
midi: "audio/x-midi",
|
|
63
|
-
mjs: "text/javascript",
|
|
64
|
-
mp3: "audio/mpeg",
|
|
65
|
-
mp4: "video/mp4",
|
|
66
|
-
mpeg: "video/mpeg",
|
|
67
|
-
oga: "audio/ogg",
|
|
68
|
-
ogv: "video/ogg",
|
|
69
|
-
ogx: "application/ogg",
|
|
70
|
-
opus: "audio/opus",
|
|
71
|
-
otf: "font/otf",
|
|
72
|
-
pdf: "application/pdf",
|
|
73
|
-
png: "image/png",
|
|
74
|
-
rtf: "application/rtf",
|
|
75
|
-
svg: "image/svg+xml",
|
|
76
|
-
tif: "image/tiff",
|
|
77
|
-
tiff: "image/tiff",
|
|
78
|
-
ts: "video/mp2t",
|
|
79
|
-
ttf: "font/ttf",
|
|
80
|
-
txt: "text/plain",
|
|
81
|
-
wasm: "application/wasm",
|
|
82
|
-
webm: "video/webm",
|
|
83
|
-
weba: "audio/webm",
|
|
84
|
-
webp: "image/webp",
|
|
85
|
-
woff: "font/woff",
|
|
86
|
-
woff2: "font/woff2",
|
|
87
|
-
xhtml: "application/xhtml+xml",
|
|
88
|
-
xml: "application/xml",
|
|
89
|
-
zip: "application/zip",
|
|
90
|
-
"3gp": "video/3gpp",
|
|
91
|
-
"3g2": "video/3gpp2",
|
|
92
|
-
gltf: "model/gltf+json",
|
|
93
|
-
glb: "model/gltf-binary"
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// src/serve-static.ts
|
|
3
|
+
import { getFilePath } from "hono/utils/filepath";
|
|
4
|
+
import { getMimeType } from "hono/utils/mime";
|
|
97
5
|
var createStreamBody = (stream) => {
|
|
98
6
|
const body = new ReadableStream({
|
|
99
7
|
start(controller) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/node-server",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.5",
|
|
4
4
|
"description": "Node.js Adapter for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"test": "node --expose-gc ./node_modules/.bin/jest",
|
|
50
|
-
"build": "tsup",
|
|
50
|
+
"build": "tsup --external hono",
|
|
51
51
|
"watch": "tsup --watch",
|
|
52
52
|
"postbuild": "publint",
|
|
53
53
|
"prerelease": "yarn build && yarn test",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@types/supertest": "^2.0.12",
|
|
79
79
|
"@whatwg-node/fetch": "^0.9.14",
|
|
80
80
|
"eslint": "^8.55.0",
|
|
81
|
-
"hono": "^4.
|
|
81
|
+
"hono": "^4.4.10",
|
|
82
82
|
"jest": "^29.6.1",
|
|
83
83
|
"np": "^7.7.0",
|
|
84
84
|
"prettier": "^3.2.4",
|