@server/next 0.20.4 → 0.20.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/package.json +1 -1
- package/src/reply.js +15 -5
package/package.json
CHANGED
package/src/reply.js
CHANGED
|
@@ -57,11 +57,16 @@ Reply.prototype.json = function (body) {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
Reply.prototype.file = async function (path) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
try {
|
|
61
|
+
const data = await fs.readFile(path);
|
|
62
|
+
const ext = path.split(".").pop();
|
|
63
|
+
return this.type(ext).send(data);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error.code === "ENOENT") {
|
|
66
|
+
return status(404).send();
|
|
67
|
+
}
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
65
70
|
};
|
|
66
71
|
|
|
67
72
|
Reply.prototype.view = async function (path) {
|
|
@@ -89,6 +94,11 @@ Reply.prototype.send = function (body = "") {
|
|
|
89
94
|
return new Response(body, { status, headers });
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
if (body?.constructor?.name === "Buffer") {
|
|
98
|
+
const headers = this.generateHeaders();
|
|
99
|
+
return new Response(body, { status, headers });
|
|
100
|
+
}
|
|
101
|
+
|
|
92
102
|
// This is a bit loopy, send({}) => json({}) => send('{}')
|
|
93
103
|
return this.json(body);
|
|
94
104
|
};
|