@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.
- package/package.json +1 -1
- package/src/index.js +27 -1
package/package.json
CHANGED
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
|
-
|
|
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
|