@server/next 0.20.16 → 0.20.18

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/index.js +27 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.20.16",
3
+ "version": "0.20.18",
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/index.js CHANGED
@@ -114,8 +114,21 @@ const extendWithDefaults = (ctx) => {
114
114
 
115
115
  // Export the main server()
116
116
  export default function server(options = {}) {
117
+ // Make it so that the exported one is a prototype of function()
117
118
  if (!(this instanceof server)) {
118
- return new server(options);
119
+ const inst = new server(options);
120
+ const cb = inst.netlify;
121
+ const keys = Object.keys(Object.getPrototypeOf(inst)).concat(
122
+ Object.keys(inst)
123
+ );
124
+ keys.forEach((key) => {
125
+ if (typeof inst[key] === "function") {
126
+ cb[key] = inst[key].bind(inst);
127
+ } else {
128
+ cb[key] = inst[key];
129
+ }
130
+ });
131
+ return cb;
119
132
  }
120
133
 
121
134
  // Skip "forbidden methods" https://fetch.spec.whatwg.org/#concept-method
@@ -165,6 +178,19 @@ export default function server(options = {}) {
165
178
  return new Response(error.message, { status: error.status || 500 });
166
179
  }
167
180
  };
181
+
182
+ this.netlify = async (request) => {
183
+ if (typeof Netlify === "undefined") throw new Error("Unknown");
184
+ console.log("Experimental Netlify");
185
+ try {
186
+ options = validateOptions(options, Netlify.env.toObject());
187
+ const ctx = await createWinterContext(request, options, this);
188
+ extendWithDefaults(ctx);
189
+ return await handleRequest(this.handlers, ctx);
190
+ } catch (error) {
191
+ return new Response(error.message, { status: error.status || 500 });
192
+ }
193
+ };
168
194
  }
169
195
 
170
196
  // INTERNAL