@server/next 0.20.18 → 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 -13
- package/src/index.test.js +18 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -117,18 +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
|
-
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;
|
|
120
|
+
return inst.self();
|
|
132
121
|
}
|
|
133
122
|
|
|
134
123
|
// Skip "forbidden methods" https://fetch.spec.whatwg.org/#concept-method
|
|
@@ -193,6 +182,17 @@ export default function server(options = {}) {
|
|
|
193
182
|
};
|
|
194
183
|
}
|
|
195
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
|
+
|
|
196
196
|
// INTERNAL
|
|
197
197
|
server.prototype.handle = function (method, path, ...middleware) {
|
|
198
198
|
if (method === "*") {
|
|
@@ -203,7 +203,7 @@ server.prototype.handle = function (method, path, ...middleware) {
|
|
|
203
203
|
this.handlers[method].push([method, path, ...middleware]);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
return this;
|
|
206
|
+
return this.self();
|
|
207
207
|
};
|
|
208
208
|
|
|
209
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")
|