@server/next 0.20.28 → 0.20.29

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.20.28",
3
+ "version": "0.20.29",
4
4
  "description": "An experimental reimplementation of server.js focused on the DX",
5
5
  "homepage": "https://node-server.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
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/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({ "content-type": "application/json" }).send(
59
- JSON.stringify(body)
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 ? "text/html" : "text/plain";
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
  });