@server/next 0.20.18 → 0.20.20
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 +14 -15
- package/src/index.test.js +18 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -116,19 +116,7 @@ const extendWithDefaults = (ctx) => {
|
|
|
116
116
|
export default function server(options = {}) {
|
|
117
117
|
// Make it so that the exported one is a prototype of function()
|
|
118
118
|
if (!(this instanceof server)) {
|
|
119
|
-
|
|
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
|
+
return new server(options).self();
|
|
132
120
|
}
|
|
133
121
|
|
|
134
122
|
// Skip "forbidden methods" https://fetch.spec.whatwg.org/#concept-method
|
|
@@ -193,6 +181,17 @@ export default function server(options = {}) {
|
|
|
193
181
|
};
|
|
194
182
|
}
|
|
195
183
|
|
|
184
|
+
server.prototype.self = function () {
|
|
185
|
+
const cb = this.netlify;
|
|
186
|
+
const keys = Object.keys(Object.getPrototypeOf(this)).concat(
|
|
187
|
+
Object.keys(this)
|
|
188
|
+
);
|
|
189
|
+
keys.forEach((key) => {
|
|
190
|
+
cb[key] = this[key];
|
|
191
|
+
});
|
|
192
|
+
return cb;
|
|
193
|
+
};
|
|
194
|
+
|
|
196
195
|
// INTERNAL
|
|
197
196
|
server.prototype.handle = function (method, path, ...middleware) {
|
|
198
197
|
if (method === "*") {
|
|
@@ -203,7 +202,7 @@ server.prototype.handle = function (method, path, ...middleware) {
|
|
|
203
202
|
this.handlers[method].push([method, path, ...middleware]);
|
|
204
203
|
}
|
|
205
204
|
|
|
206
|
-
return this;
|
|
205
|
+
return this.self();
|
|
207
206
|
};
|
|
208
207
|
|
|
209
208
|
server.prototype.socket = function (path, ...middleware) {
|
|
@@ -252,7 +251,7 @@ server.prototype.router = function (basePath, router) {
|
|
|
252
251
|
this.handle(method, basePath + path.replace(/^\//, ""), ...callbacks);
|
|
253
252
|
});
|
|
254
253
|
}
|
|
255
|
-
return this;
|
|
254
|
+
return this.self();
|
|
256
255
|
};
|
|
257
256
|
|
|
258
257
|
server.prototype.test = function () {
|
package/src/index.test.js
CHANGED
|
@@ -2,6 +2,24 @@ import "./test/toSucceed.js";
|
|
|
2
2
|
|
|
3
3
|
import server, { status } from "./index.js";
|
|
4
4
|
|
|
5
|
+
describe("exports", () => {
|
|
6
|
+
it("exports as a function", () => {
|
|
7
|
+
expect(typeof server()).toBe("function");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("nested is also a function", () => {
|
|
11
|
+
expect(typeof server().get("/", () => {})).toBe("function");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("export has a fetch", () => {
|
|
15
|
+
expect(typeof server().fetch).toBe("function");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("nested is also a function", () => {
|
|
19
|
+
expect(typeof server().get("/", () => {}).fetch).toBe("function");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
5
23
|
describe("return different types", () => {
|
|
6
24
|
const api = server()
|
|
7
25
|
.get("/", () => "Hello world")
|