@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/reply.js +15 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.20.4",
3
+ "version": "0.20.5",
4
4
  "description": "An experimental reimplementation of server.js focused on the DX",
5
5
  "homepage": "https://node-server.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
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
- const data = await fs.readFile(path);
61
- if (!data) return status(404).send();
62
-
63
- this.type(path.split(".").pop());
64
- return new Response(data, { status: 200, headers: this.res.headers });
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
  };