@server/next 0.17.0 → 0.17.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.17.0",
3
+ "version": "0.17.3",
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/readme.md CHANGED
@@ -49,7 +49,7 @@ Major changes:
49
49
 
50
50
  - Router has all verbs, as well as URL pattern matches
51
51
  - Full URL parsing, including `query` and `params` in ctx.url.
52
- - Body and Files parsing is working (TODO: try with binary files and add tests)
52
+ - Body and Files parsing is working (need testing)
53
53
  - The middleware can return:
54
54
  - A number and it'll be set as the status code
55
55
  - A string and it'll be sent as plain text or html (if it starts with "<")
@@ -70,7 +70,7 @@ import Redis from 'redis';
70
70
  const bucket = Bucket('my-bucket', { id, key });
71
71
  const cache = Redis('my-redis', ...);
72
72
 
73
- const app = server({ public: bucket, cache });
73
+ const app = server({ public: bucket, uploads: bucket, cache });
74
74
 
75
75
  app([
76
76
  post('/uploads', ctx => {
package/src/index.js CHANGED
@@ -146,8 +146,8 @@ const parseOutput = async (res, data) => {
146
146
 
147
147
  // When piping the output
148
148
  if (data.pipe) {
149
- res.body = data;
150
149
  res.status = 200;
150
+ res.body = data;
151
151
  // It's a file; find its mimetype
152
152
  if (res.body.path) {
153
153
  res.type = await getMime(res.body.path);
@@ -159,7 +159,7 @@ const parseOutput = async (res, data) => {
159
159
  if (data.type) res.type = data.type;
160
160
  res.headers = { ...res.headers, ...(data.headers || {}) };
161
161
  res.body = data.body || ""; // This could also be a pipe and that's okay
162
- res.status = data.status || 200;
162
+ res.status = data.status || 200; // user set > default
163
163
  return res;
164
164
  };
165
165
 
@@ -184,14 +184,15 @@ export default function (options = {}, plugins) {
184
184
 
185
185
  let out;
186
186
  let err;
187
- ctx.res = { headers: {} };
187
+ // Will (hopefully) be overwritten later on!
188
+ ctx.res = { status: 500, headers: {} };
188
189
  for (let cb of app.middleware) {
189
190
  try {
190
191
  if (err) {
191
192
  if (cb.handle) {
192
193
  out = await cb.handle(err);
193
194
  }
194
- } else {
195
+ } else if (typeof cb === "function") {
195
196
  out = await cb(ctx);
196
197
  }
197
198
  if (out) {
@@ -226,8 +227,8 @@ export default function (options = {}, plugins) {
226
227
  res.writeHead(ctx.res.status, ctx.res.headers);
227
228
 
228
229
  // If it's not a pipe, e.g. a String, make it a pipe
229
- if (!ctx.res.body.pipe) {
230
- ctx.res.body = Readable.from([ctx.res.body]);
230
+ if (!ctx.res.body || !ctx.res.body.pipe) {
231
+ ctx.res.body = Readable.from([ctx.res.body || ""]);
231
232
  }
232
233
 
233
234
  if (compress) {