@server/next 0.20.16 → 0.20.17
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/index.js +23 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -114,8 +114,17 @@ 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
|
-
|
|
119
|
+
const inst = new server(options);
|
|
120
|
+
const cb = inst.netlify;
|
|
121
|
+
Object.keys(Object.getPrototypeOf(inst)).forEach((key) => {
|
|
122
|
+
cb[key] = inst[key];
|
|
123
|
+
});
|
|
124
|
+
Object.keys(inst).forEach((key) => {
|
|
125
|
+
cb[key] = inst[key];
|
|
126
|
+
});
|
|
127
|
+
return cb;
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
// Skip "forbidden methods" https://fetch.spec.whatwg.org/#concept-method
|
|
@@ -165,6 +174,19 @@ export default function server(options = {}) {
|
|
|
165
174
|
return new Response(error.message, { status: error.status || 500 });
|
|
166
175
|
}
|
|
167
176
|
};
|
|
177
|
+
|
|
178
|
+
this.netlify = async (request) => {
|
|
179
|
+
if (typeof Netlify === "undefined") throw new Error("Unknown");
|
|
180
|
+
console.log("Experimental Netlify");
|
|
181
|
+
try {
|
|
182
|
+
options = validateOptions(options, Netlify.env.toObject());
|
|
183
|
+
const ctx = await createWinterContext(request, options, this);
|
|
184
|
+
extendWithDefaults(ctx);
|
|
185
|
+
return await handleRequest(this.handlers, ctx);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
return new Response(error.message, { status: error.status || 500 });
|
|
188
|
+
}
|
|
189
|
+
};
|
|
168
190
|
}
|
|
169
191
|
|
|
170
192
|
// INTERNAL
|