@server/next 0.20.28 → 0.20.30
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 +1 -1
- package/src/index.test.js +3 -2
- package/src/polyfill.js +4 -18
- package/src/reply.js +6 -4
- package/src/url.test.js +2 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -259,7 +259,7 @@ server.prototype.test = function () {
|
|
|
259
259
|
const fetch = async (path, options = {}) => {
|
|
260
260
|
if (!options.headers) options.headers = {};
|
|
261
261
|
if (options.body && typeof options.body !== "string") {
|
|
262
|
-
options.headers["content-type"] = "application/json";
|
|
262
|
+
options.headers["content-type"] = "application/json; charset=utf-8";
|
|
263
263
|
options.body = JSON.stringify(options.body);
|
|
264
264
|
}
|
|
265
265
|
if (cookie && !options.headers.cookie) {
|
package/src/index.test.js
CHANGED
|
@@ -57,15 +57,16 @@ describe("simple post works", () => {
|
|
|
57
57
|
.test();
|
|
58
58
|
|
|
59
59
|
it("can post new data", async () => {
|
|
60
|
-
const { data, status } = await api.post("/", "New Data");
|
|
60
|
+
const { data, status, headers } = await api.post("/", "New Data");
|
|
61
61
|
expect(status).toBe(201);
|
|
62
62
|
expect(data).toBe("New Data");
|
|
63
|
+
expect(headers["content-type"]).toBe("text/plain; charset=utf-8");
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
it("will return JSON", async () => {
|
|
66
67
|
const { data, status, headers } = await api.post("/", { hello: "world" });
|
|
67
68
|
expect(status).toBe(201);
|
|
68
69
|
expect(data).toEqual({ hello: "world" });
|
|
69
|
-
expect(headers["content-type"]).toBe("application/json");
|
|
70
|
+
expect(headers["content-type"]).toBe("application/json; charset=utf-8");
|
|
70
71
|
});
|
|
71
72
|
});
|
package/src/polyfill.js
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
const self =
|
|
2
|
-
typeof globalThis !== "undefined"
|
|
3
|
-
? globalThis
|
|
4
|
-
: typeof global !== "undefined"
|
|
5
|
-
? global
|
|
6
|
-
: typeof window !== "undefined"
|
|
7
|
-
? window
|
|
8
|
-
: null;
|
|
9
|
-
|
|
10
1
|
// out = new Response(out, { headers: { "content-type": type } });
|
|
11
2
|
if (typeof Response === "undefined") {
|
|
12
|
-
|
|
3
|
+
global.Response = function Response(body, other = {}) {
|
|
13
4
|
return { body, ...other };
|
|
14
5
|
};
|
|
15
6
|
}
|
|
16
7
|
|
|
17
8
|
// Polyfill Netlify's environment variables
|
|
18
|
-
if (typeof Netlify !== "undefined") {
|
|
19
|
-
if (!
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
if (!self.process.env) {
|
|
23
|
-
self.process.env = {};
|
|
24
|
-
}
|
|
25
|
-
Object.assign(self.process.env, Netlify.env.toObject());
|
|
9
|
+
if (typeof Netlify !== "undefined" && typeof import.meta !== "undefined") {
|
|
10
|
+
if (!import.meta.env) import.meta.env = {};
|
|
11
|
+
Object.assign(import.meta.env, Netlify.env.toObject());
|
|
26
12
|
}
|
package/src/reply.js
CHANGED
|
@@ -55,9 +55,9 @@ Reply.prototype.cookies = function (cookies) {
|
|
|
55
55
|
|
|
56
56
|
// FINAL
|
|
57
57
|
Reply.prototype.json = function (body) {
|
|
58
|
-
return this.headers({
|
|
59
|
-
|
|
60
|
-
);
|
|
58
|
+
return this.headers({
|
|
59
|
+
"content-type": "application/json; charset=utf-8",
|
|
60
|
+
}).send(JSON.stringify(body));
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
Reply.prototype.file = async function (path) {
|
|
@@ -91,7 +91,9 @@ Reply.prototype.send = function (body = "") {
|
|
|
91
91
|
// Not yet set, so infer the type from type of string
|
|
92
92
|
if (!this.res.headers["content-type"]) {
|
|
93
93
|
const isHtml = body.startsWith("<");
|
|
94
|
-
this.res.headers["content-type"] = isHtml
|
|
94
|
+
this.res.headers["content-type"] = isHtml
|
|
95
|
+
? "text/html; charset=utf-8"
|
|
96
|
+
: "text/plain; charset=utf-8";
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
const headers = this.generateHeaders();
|
package/src/url.test.js
CHANGED
|
@@ -9,7 +9,7 @@ describe("can match the url", () => {
|
|
|
9
9
|
|
|
10
10
|
const { data, headers } = await api.get("/hello");
|
|
11
11
|
expect(data).toEqual({ id: "hello" });
|
|
12
|
-
expect(headers["content-type"]).toEqual("application/json");
|
|
12
|
+
expect(headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it("but it doesn't if it's a use", async () => {
|
|
@@ -21,6 +21,6 @@ describe("can match the url", () => {
|
|
|
21
21
|
|
|
22
22
|
const { data, headers, ...rest } = await api.get("/hello");
|
|
23
23
|
expect(data).toEqual({ id: "hello" });
|
|
24
|
-
expect(headers["content-type"]).toEqual("application/json");
|
|
24
|
+
expect(headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
25
25
|
});
|
|
26
26
|
});
|