@server/next 0.20.17 → 0.20.19
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 +13 -9
- package/src/index.test.js +18 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -117,14 +117,7 @@ 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
119
|
const inst = new server(options);
|
|
120
|
-
|
|
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;
|
|
120
|
+
return inst.self();
|
|
128
121
|
}
|
|
129
122
|
|
|
130
123
|
// Skip "forbidden methods" https://fetch.spec.whatwg.org/#concept-method
|
|
@@ -189,6 +182,17 @@ export default function server(options = {}) {
|
|
|
189
182
|
};
|
|
190
183
|
}
|
|
191
184
|
|
|
185
|
+
server.prototype.self = function () {
|
|
186
|
+
const cb = this.netlify;
|
|
187
|
+
const keys = Object.keys(Object.getPrototypeOf(this)).concat(
|
|
188
|
+
Object.keys(this)
|
|
189
|
+
);
|
|
190
|
+
keys.forEach((key) => {
|
|
191
|
+
cb[key] = this[key];
|
|
192
|
+
});
|
|
193
|
+
return cb;
|
|
194
|
+
};
|
|
195
|
+
|
|
192
196
|
// INTERNAL
|
|
193
197
|
server.prototype.handle = function (method, path, ...middleware) {
|
|
194
198
|
if (method === "*") {
|
|
@@ -199,7 +203,7 @@ server.prototype.handle = function (method, path, ...middleware) {
|
|
|
199
203
|
this.handlers[method].push([method, path, ...middleware]);
|
|
200
204
|
}
|
|
201
205
|
|
|
202
|
-
return this;
|
|
206
|
+
return this.self();
|
|
203
207
|
};
|
|
204
208
|
|
|
205
209
|
server.prototype.socket = function (path, ...middleware) {
|
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")
|