jeasx 2.2.0 → 2.2.2
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/CHANGELOG.md +26 -6
- package/LICENSE.txt +1 -1
- package/package.json +7 -7
- package/serverless.js +6 -6
- package/serverless.js.map +1 -1
- package/serverless.ts +19 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026-01-17 - Jeasx 2.2.2 released
|
|
4
|
+
|
|
5
|
+
🎉 This release now preserves the original status code when a 404 page is accessed directly (previously defaulted to 200). This improvement makes it easier to use Jeasx as a static site generator and to fetch the 404 page with common tools for saving it to a file system. While Jeasx is fundamentally a server-side rendering framework, there are valid use cases where serving a static page alone is sufficient.
|
|
6
|
+
|
|
7
|
+
For example, you can use `wget` to download a Jeasx website to a www-directory with just a single line:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
wget --mirror --page-requisites --no-host-directories --directory-prefix=www http://localhost:3000 http://localhost:3000/404
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Have a look at the [Dockerfile](https://github.com/jeasx/jeasx-website/blob/main/Dockerfile) of the Jeasx website to see how things can be wired up for serving a static export with Caddy as web server.
|
|
14
|
+
|
|
15
|
+
Dependency updates: `fastify@5.7.1`, `@fastify/static@9.0.0`, `@types/node@24.10.9`
|
|
16
|
+
|
|
17
|
+
## 2025-12-21 - Jeasx 2.2.1 released
|
|
18
|
+
|
|
19
|
+
🎉 Just a patch release with a minor cleanup for explicit path joins in `serverless.ts`.
|
|
20
|
+
|
|
21
|
+
Dependency updates: `esbuild@0.27.2`, `jsx-async-runtime@2.0.2`, `@types/node@24.10.4`
|
|
22
|
+
|
|
3
23
|
## 2025-12-01 - Jeasx 2.2.0 released
|
|
4
24
|
|
|
5
25
|
🎉 This release introduces a more flexible configuration approach for the underlying Fastify server. You can now customize all Fastify options (including those for all used plugins) according to your needs, without having to use the formerly fixed and very restrictive set of environment variables. This change was made to eliminate the need for increasingly specific environment variables to customise the default behaviour of Jeasx.
|
|
@@ -8,11 +28,11 @@
|
|
|
8
28
|
|
|
9
29
|
To configure Fastify (or a specific plugin), you can now use simple JSON objects which mirror the corresponding Fastify options. Have a look at the linked Fastify documentation for a reference of all existing options:
|
|
10
30
|
|
|
11
|
-
- [`FASTIFY_SERVER_OPTIONS`](
|
|
12
|
-
- [`FASTIFY_COOKIE_OPTIONS`](
|
|
13
|
-
- [`FASTIFY_FORMBODY_OPTIONS`](
|
|
14
|
-
- [`FASTIFY_MULTIPART_OPTIONS`](
|
|
15
|
-
- [`FASTIFY_STATIC_OPTIONS`](
|
|
31
|
+
- [`FASTIFY_SERVER_OPTIONS`](https://fastify.dev/docs/latest/Reference/Server/)
|
|
32
|
+
- [`FASTIFY_COOKIE_OPTIONS`](https://github.com/fastify/fastify-cookie#options)
|
|
33
|
+
- [`FASTIFY_FORMBODY_OPTIONS`](https://github.com/fastify/fastify-formbody#options)
|
|
34
|
+
- [`FASTIFY_MULTIPART_OPTIONS`](https://github.com/fastify/fastify-multipart#options)
|
|
35
|
+
- [`FASTIFY_STATIC_OPTIONS`](https://github.com/fastify/fastify-static#options)
|
|
16
36
|
|
|
17
37
|
To optimise the developer experience, it is highly recommended that you use the recently introduced `.env.js` file to provide these configuration options. Alternatively, you can also provide them via `.env` or your process environment. Jeasx comes with a minimal set of reasonable [Fastify defaults](https://github.com/jeasx/jeasx/blob/main/serverless.ts), but you can also overwrite them if necessary.
|
|
18
38
|
|
|
@@ -323,7 +343,7 @@ Added two new environment variables (`FASTIFY_DISABLE_REQUEST_LOGGING` and `FAST
|
|
|
323
343
|
|
|
324
344
|
## 2024-12-01 - Jeasx 1.1.0 released
|
|
325
345
|
|
|
326
|
-
🎉 Migrated from dotenv to dotenv-flow, so you can use NODE_ENV-specific .env
|
|
346
|
+
🎉 Migrated from dotenv to dotenv-flow, so you can use NODE_ENV-specific .env\* files (like `.env.development`) to configure different environments for production and development. This is useful to disable caching headers (e.g. via `FASTIFY_STATIC_HEADERS`) in development, as Jeasx applies `FASTIFY_STATIC_HEADERS` in development from now on for a more consistent developer expierence. See updated .env-files in the quickstart-project for an example how to disable caching in development. This is only needed if you have configured `FASTIFY_STATIC_HEADERS` for your existing projects.
|
|
327
347
|
|
|
328
348
|
Bumped default environment variable `ESBUILD_BROWSER_TARGET` to more recent browser versions (e.g. `chrome126, edge126, firefox128, safari17`). If you want to stick with older versions, you can override it via the environment. Learn more about possible values at the esbuild website.
|
|
329
349
|
|
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2024-
|
|
3
|
+
Copyright (c) 2024-2026 Maik Jablonski (<mail@jeasx.dev>)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jeasx",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Jeasx - the ease of JSX with the power of SSR",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsx",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"fastify"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://www.jeasx.dev",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "https://github.com/jeasx/jeasx.git"
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"@fastify/cookie": "11.0.2",
|
|
28
28
|
"@fastify/formbody": "8.0.2",
|
|
29
29
|
"@fastify/multipart": "9.3.0",
|
|
30
|
-
"@fastify/static": "
|
|
31
|
-
"@types/node": "24.10.
|
|
32
|
-
"esbuild": "0.27.
|
|
33
|
-
"fastify": "5.
|
|
34
|
-
"jsx-async-runtime": "2.0.
|
|
30
|
+
"@fastify/static": "9.0.0",
|
|
31
|
+
"@types/node": "24.10.9",
|
|
32
|
+
"esbuild": "0.27.2",
|
|
33
|
+
"fastify": "5.7.1",
|
|
34
|
+
"jsx-async-runtime": "2.0.2"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "esbuild --platform=node --format=esm --sourcemap=linked --sources-content=false --outdir=. serverless.ts"
|
package/serverless.js
CHANGED
|
@@ -14,9 +14,7 @@ const NODE_ENV_IS_DEVELOPMENT = process.env.NODE_ENV === "development";
|
|
|
14
14
|
const JEASX_ROUTE_CACHE_LIMIT = Math.floor(freemem() / 1024 / 1024);
|
|
15
15
|
var serverless_default = Fastify({
|
|
16
16
|
logger: true,
|
|
17
|
-
...jsonToOptions(
|
|
18
|
-
process.env.FASTIFY_SERVER_OPTIONS
|
|
19
|
-
)
|
|
17
|
+
...jsonToOptions(process.env.FASTIFY_SERVER_OPTIONS)
|
|
20
18
|
}).register(fastifyCookie, {
|
|
21
19
|
...jsonToOptions(
|
|
22
20
|
process.env.FASTIFY_COOKIE_OPTIONS
|
|
@@ -31,7 +29,7 @@ var serverless_default = Fastify({
|
|
|
31
29
|
process.env.FASTIFY_MULTIPART_OPTIONS
|
|
32
30
|
)
|
|
33
31
|
}).register(fastifyStatic, {
|
|
34
|
-
root: ["public", "dist
|
|
32
|
+
root: [["public"], ["dist", "browser"]].map((dir) => join(CWD, ...dir)),
|
|
35
33
|
prefix: "/",
|
|
36
34
|
wildcard: false,
|
|
37
35
|
preCompressed: true,
|
|
@@ -75,7 +73,7 @@ async function handler(request, reply) {
|
|
|
75
73
|
}
|
|
76
74
|
if (module === void 0) {
|
|
77
75
|
try {
|
|
78
|
-
const modulePath = join(CWD, "dist",
|
|
76
|
+
const modulePath = join(CWD, "dist", "server", `${route}.js`);
|
|
79
77
|
if (NODE_ENV_IS_DEVELOPMENT) {
|
|
80
78
|
if (typeof require === "function") {
|
|
81
79
|
if (require.cache[modulePath]) {
|
|
@@ -110,7 +108,9 @@ async function handler(request, reply) {
|
|
|
110
108
|
if (reply.sent) {
|
|
111
109
|
return;
|
|
112
110
|
} else if (route.endsWith("/[404]")) {
|
|
113
|
-
reply.
|
|
111
|
+
if (reply.statusCode === 200 && !request.path.endsWith("/404")) {
|
|
112
|
+
reply.status(404);
|
|
113
|
+
}
|
|
114
114
|
break;
|
|
115
115
|
} else if (typeof response === "string" || Buffer.isBuffer(response) || isJSX(response)) {
|
|
116
116
|
break;
|
package/serverless.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["serverless.ts"],
|
|
4
|
-
"mappings": "AAAA,OAAO,mBAA6C;AACpD,OAAO,qBAAiD;AACxD,OAAO,sBAAmD;AAC1D,OAAO,mBAA6C;AACpD,OAAO,aAIA;AACP,SAAS,mBAAmB;AAC5B,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,OAAO,SAAS;AAEhB,MAAM,IAAI;AAEV,MAAM,MAAM,QAAQ,IAAI;AACxB,MAAM,0BAA0B,QAAQ,IAAI,aAAa;AACzD,MAAM,0BAA0B,KAAK,MAAM,QAAQ,IAAI,OAAO,IAAI;AAUlE,IAAO,qBAAQ,QAAQ;AAAA,EACrB,QAAQ;AAAA,EACR,GAAI
|
|
4
|
+
"mappings": "AAAA,OAAO,mBAA6C;AACpD,OAAO,qBAAiD;AACxD,OAAO,sBAAmD;AAC1D,OAAO,mBAA6C;AACpD,OAAO,aAIA;AACP,SAAS,mBAAmB;AAC5B,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,OAAO,SAAS;AAEhB,MAAM,IAAI;AAEV,MAAM,MAAM,QAAQ,IAAI;AACxB,MAAM,0BAA0B,QAAQ,IAAI,aAAa;AACzD,MAAM,0BAA0B,KAAK,MAAM,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ACF;AAQA,SAAS,iBAAiB,MAAwB;AAChD,SAAO,KACJ,MAAM,GAAG,EACT,OAAO,CAAC,YAAY,YAAY,EAAE,EAClC,OAAO,CAAC,KAAK,YAAY;AACxB,QAAI,MAAM,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,CAAC,IAAI,MAAM,MAAM,OAAO;AACpE,WAAO;AAAA,EACT,GAAG,CAAC,CAAC,EACJ,QAAQ,EACR,OAAO,EAAE;AACd;AAQA,SAAS,cAAc,MAAwB;AAC7C,QAAM,QAAQ,CAAC;AACf,MAAI,MAAM;AACR,UAAM,cAAc,KAAK,YAAY,GAAG,IAAI;AAC5C,UAAM;AAAA,MACJ,GAAG,KAAK,UAAU,GAAG,WAAW,CAAC,IAAI,KAAK,UAAU,WAAW,CAAC;AAAA,IAClE;AAAA,EACF;AACA,QAAM,KAAK,GAAG,IAAI,UAAU;AAC5B,SAAO;AACT;AAKA,SAAS,MAAM,KAAuB;AACpC,SAAO,CAAC,CAAC,OAAO,OAAO,QAAQ,YAAY,UAAU,OAAO,WAAW;AACzE;AAKA,eAAe,UAAU,SAAiB,UAAmB;AAC3D,QAAM,UACJ,MAAM,QAAQ,IAAI,MAAM,YAAY,KAAK,SAAS,QAAQ,IAAI;AAGhE,QAAM,kBAAkB,QAAQ,iBAAiB;AACjD,SAAO,OAAO,oBAAoB,aAC9B,MAAM,gBAAgB,KAAK,SAAS,OAAO,IAC3C;AACN;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/serverless.ts
CHANGED
|
@@ -5,7 +5,7 @@ import fastifyStatic, { FastifyStaticOptions } from "@fastify/static";
|
|
|
5
5
|
import Fastify, {
|
|
6
6
|
FastifyReply,
|
|
7
7
|
FastifyRequest,
|
|
8
|
-
FastifyServerOptions
|
|
8
|
+
FastifyServerOptions
|
|
9
9
|
} from "fastify";
|
|
10
10
|
import { jsxToString } from "jsx-async-runtime";
|
|
11
11
|
import { stat } from "node:fs/promises";
|
|
@@ -29,34 +29,32 @@ declare module "fastify" {
|
|
|
29
29
|
// Create and export a Fastify app instance
|
|
30
30
|
export default Fastify({
|
|
31
31
|
logger: true,
|
|
32
|
-
...(jsonToOptions(
|
|
33
|
-
process.env.FASTIFY_SERVER_OPTIONS
|
|
34
|
-
) as FastifyServerOptions),
|
|
32
|
+
...(jsonToOptions(process.env.FASTIFY_SERVER_OPTIONS) as FastifyServerOptions)
|
|
35
33
|
})
|
|
36
34
|
.register(fastifyCookie, {
|
|
37
35
|
...(jsonToOptions(
|
|
38
36
|
process.env.FASTIFY_COOKIE_OPTIONS
|
|
39
|
-
) as FastifyCookieOptions)
|
|
37
|
+
) as FastifyCookieOptions)
|
|
40
38
|
})
|
|
41
39
|
.register(fastifyFormbody, {
|
|
42
40
|
...(jsonToOptions(
|
|
43
41
|
process.env.FASTIFY_FORMBODY_OPTIONS
|
|
44
|
-
) as FastifyFormbodyOptions)
|
|
42
|
+
) as FastifyFormbodyOptions)
|
|
45
43
|
})
|
|
46
44
|
.register(fastifyMultipart, {
|
|
47
45
|
attachFieldsToBody: "keyValues",
|
|
48
46
|
...(jsonToOptions(
|
|
49
47
|
process.env.FASTIFY_MULTIPART_OPTIONS
|
|
50
|
-
) as FastifyMultipartOptions)
|
|
48
|
+
) as FastifyMultipartOptions)
|
|
51
49
|
})
|
|
52
50
|
.register(fastifyStatic, {
|
|
53
|
-
root: ["public", "dist
|
|
51
|
+
root: [["public"], ["dist", "browser"]].map((dir) => join(CWD, ...dir)),
|
|
54
52
|
prefix: "/",
|
|
55
53
|
wildcard: false,
|
|
56
54
|
preCompressed: true,
|
|
57
55
|
...(jsonToOptions(
|
|
58
56
|
process.env.FASTIFY_STATIC_OPTIONS
|
|
59
|
-
) as FastifyStaticOptions)
|
|
57
|
+
) as FastifyStaticOptions)
|
|
60
58
|
})
|
|
61
59
|
.decorateRequest("route", "")
|
|
62
60
|
.decorateRequest("path", "")
|
|
@@ -119,7 +117,7 @@ async function handler(request: FastifyRequest, reply: FastifyReply) {
|
|
|
119
117
|
// Module was not loaded yet?
|
|
120
118
|
if (module === undefined) {
|
|
121
119
|
try {
|
|
122
|
-
const modulePath = join(CWD, "dist",
|
|
120
|
+
const modulePath = join(CWD, "dist", "server", `${route}.js`);
|
|
123
121
|
if (NODE_ENV_IS_DEVELOPMENT) {
|
|
124
122
|
if (typeof require === "function") {
|
|
125
123
|
// Bun: Remove module from cache before importing
|
|
@@ -159,13 +157,17 @@ async function handler(request: FastifyRequest, reply: FastifyReply) {
|
|
|
159
157
|
response = await module.default.call(context, {
|
|
160
158
|
request,
|
|
161
159
|
reply,
|
|
162
|
-
...(typeof response === "object" ? response : {})
|
|
160
|
+
...(typeof response === "object" ? response : {})
|
|
163
161
|
});
|
|
164
162
|
|
|
165
163
|
if (reply.sent) {
|
|
166
164
|
return;
|
|
167
165
|
} else if (route.endsWith("/[404]")) {
|
|
168
|
-
|
|
166
|
+
// Preserve existing status if a 404 page is requested directly.
|
|
167
|
+
// If no status is defined, set status to 404 automatically.
|
|
168
|
+
if (reply.statusCode === 200 && !request.path.endsWith("/404")) {
|
|
169
|
+
reply.status(404);
|
|
170
|
+
}
|
|
169
171
|
break;
|
|
170
172
|
} else if (
|
|
171
173
|
typeof response === "string" ||
|
|
@@ -213,7 +215,7 @@ function generateRoutes(path: string): string[] {
|
|
|
213
215
|
.map((segment) => `${segment}/[...guard]`),
|
|
214
216
|
...edges.map((edge) => `${edge}`),
|
|
215
217
|
...segments.map((segment) => `${segment}/[...path]`),
|
|
216
|
-
...segments.map((segment) => `${segment}/[404]`)
|
|
218
|
+
...segments.map((segment) => `${segment}/[404]`)
|
|
217
219
|
];
|
|
218
220
|
}
|
|
219
221
|
|
|
@@ -264,13 +266,12 @@ function isJSX(obj: unknown): boolean {
|
|
|
264
266
|
* Renders JSX to string and applies optional response handler.
|
|
265
267
|
*/
|
|
266
268
|
async function renderJSX(context: object, response: unknown) {
|
|
267
|
-
const payload =
|
|
268
|
-
? await jsxToString.call(context, response)
|
|
269
|
-
: response;
|
|
269
|
+
const payload =
|
|
270
|
+
isJSX(response) ? await jsxToString.call(context, response) : response;
|
|
270
271
|
|
|
271
272
|
// Post-process the payload with an optional response handler
|
|
272
273
|
const responseHandler = context["responseHandler"];
|
|
273
|
-
return typeof responseHandler === "function"
|
|
274
|
-
|
|
274
|
+
return typeof responseHandler === "function" ?
|
|
275
|
+
await responseHandler.call(context, payload)
|
|
275
276
|
: payload;
|
|
276
277
|
}
|