@server/next 0.21.7 → 0.21.9
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/helpers/jsx.js +5 -1
- package/src/index.js +2 -1
- package/src/middle/index.js +2 -1
- package/src/middle/timer.js +5 -0
- package/src/parseResponse.js +12 -0
- package/src/router.test.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.9",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
package/src/helpers/jsx.js
CHANGED
|
@@ -13,6 +13,9 @@ const altAttrs = {
|
|
|
13
13
|
classname: "class",
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
// "" and 0 are valid children, false and null and undefined are not
|
|
17
|
+
const isValidChild = (child) => child || child === "" || child === 0;
|
|
18
|
+
|
|
16
19
|
const minifyCss = (str) =>
|
|
17
20
|
str
|
|
18
21
|
.replace(/\s+/g, " ")
|
|
@@ -44,7 +47,8 @@ export const jsx = (tag, { children, ...props }) => {
|
|
|
44
47
|
}
|
|
45
48
|
if (props.dangerouslySetInnerHTML)
|
|
46
49
|
children = () => props.dangerouslySetInnerHTML.__html;
|
|
47
|
-
|
|
50
|
+
|
|
51
|
+
if (!isValidChild(children)) children = [];
|
|
48
52
|
if (typeof children === "string") children = [children];
|
|
49
53
|
children = (Array.isArray(children) ? children : [children])
|
|
50
54
|
.flat()
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
parseHeaders,
|
|
12
12
|
} from "./helpers/index.js";
|
|
13
13
|
|
|
14
|
-
import { assets, auth } from "./middle/index.js";
|
|
14
|
+
import { assets, auth, timer } from "./middle/index.js";
|
|
15
15
|
|
|
16
16
|
// Export the reply helpers
|
|
17
17
|
export * from "./reply.js";
|
|
@@ -74,6 +74,7 @@ export default function server(options = {}) {
|
|
|
74
74
|
this.node();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
this.use(timer);
|
|
77
78
|
this.use(assets);
|
|
78
79
|
if (this.opts.auth) {
|
|
79
80
|
this.use(auth({ options: this.opts, app: this }));
|
package/src/middle/index.js
CHANGED
package/src/parseResponse.js
CHANGED
|
@@ -46,6 +46,18 @@ export default async function parseResponse(out, ctx) {
|
|
|
46
46
|
out.headers.set("Access-Control-Allow-Methods", methods);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// Only attach the headers if the user is using the timing API
|
|
50
|
+
// 1 item is the `init` so it doesn't count
|
|
51
|
+
if (ctx.time.times.length > 1) {
|
|
52
|
+
const r = (t) => Math.round(t);
|
|
53
|
+
const times = ctx.time.times;
|
|
54
|
+
const timing = times
|
|
55
|
+
.slice(1)
|
|
56
|
+
.map(([name, time], i) => `${name};dur=${r(time - times[i][1])}`)
|
|
57
|
+
.join(", ");
|
|
58
|
+
out.headers.set("Server-Timing", timing);
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
// If we have a session, we need to persist it into a cookie
|
|
50
62
|
if (Object.keys(ctx.session || {}).length) {
|
|
51
63
|
if (!ctx.options.session?.store) {
|
package/src/router.test.js
CHANGED
|
@@ -15,7 +15,7 @@ describe("can route properly", () => {
|
|
|
15
15
|
// INTERNAL - so this might change in the future
|
|
16
16
|
it("has the correct structure", () => {
|
|
17
17
|
const registeredPaths = app.handlers.get.map((h) => h[1]);
|
|
18
|
-
expect(registeredPaths).toEqual(["*", "/hello", "/api/hello", "/"]);
|
|
18
|
+
expect(registeredPaths).toEqual(["*", "*", "/hello", "/api/hello", "/"]);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it("can get fallback when nothing matches", async () => {
|