jeasx 2.2.1 → 2.3.0
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 +77 -8
- package/LICENSE.txt +1 -1
- package/env.js +17 -29
- package/esbuild.config.js +29 -13
- package/package.json +6 -5
- package/server.js +1 -1
- package/serverless.js +9 -30
- package/serverless.js.map +1 -1
- package/serverless.ts +18 -42
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026-01-30 - Jeasx 2.3.0 released
|
|
4
|
+
|
|
5
|
+
🎉 This release introduces support for [MDX](https://mdxjs.com), enabling you to seamlessly embed JSX within Markdown content. Just create a route with a `.mdx` extension, and you’re all set to enhance your websites and blogs with Markdown enriched by dynamic JSX components.
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import Layout from "./Layout"
|
|
9
|
+
|
|
10
|
+
<Layout title="MDX - Markdown for the component era">
|
|
11
|
+
# MDX as content companion alongside JSX
|
|
12
|
+
|
|
13
|
+
You can easily access existing `props` in MDX:
|
|
14
|
+
|
|
15
|
+
- Current url: {props.request.url}
|
|
16
|
+
</Layout>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
You can also create MDX-based components for use within JSX by importing them with their full `.mdx` file extension into your JSX routes or components.
|
|
20
|
+
|
|
21
|
+
Since MDX supports a variety of plugins - and Jeasx provides only the MDX core to stay focused on infrastructure while letting users handle customization - the overall configuration for Jeasx has been significantly improved. Now, the configuration object from an `.env.js` file is imported directly into both the build process and server runtime, allowing you to use package imports seamlessly. Previously, (de)serializing the configuration via `process.env` restricted this capability and limited advanced setups.
|
|
22
|
+
|
|
23
|
+
**Please note:** Variables loaded from `.env.js` now consistently overwrite any existing environment variables. This ensures predictable and consistent behavior across your configuration.
|
|
24
|
+
|
|
25
|
+
Here’s an example of how to configure the MDX engine: if you want to enable GitHub-flavored Markdown (`remark-gfm`), add syntax highlighting (`rehype-prism-plus`), and generate IDs for your headings (`rehype-slug`), you can install and configure these plugins accordingly in `.env.js`.
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import rehypePrismPlus from "rehype-prism-plus";
|
|
29
|
+
import rehypeSlug from "rehype-slug";
|
|
30
|
+
import remarkGFM from "remark-gfm";
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
/** @type import("@mdx-js/esbuild").Options */
|
|
34
|
+
ESBUILD_MDX_OPTIONS: {
|
|
35
|
+
remarkPlugins: [[remarkGFM, { singleTilde: false }]],
|
|
36
|
+
rehypePlugins: [rehypePrismPlus, [rehypeSlug, { prefix: "jeasx-" }]]
|
|
37
|
+
}
|
|
38
|
+
//...
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For a full overview of available configuration options and plugins, check out the excellent documentation of [@mdx-js/esbuild](https://mdxjs.com/packages/esbuild).
|
|
43
|
+
|
|
44
|
+
**Please note:** The update to the Jeasx configuration introduced a minor change in how `ESBUILD_BROWSER_TARGET` is specified to ensure consistency across the configuration. Previously, a comma-separated string was accepted and parsed as customization. Going forward, you must provide a proper JSON array (or its stringified form when using traditional `.env` files or the process environment).
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
export default {
|
|
48
|
+
/** @type import("esbuild").BuildOptions["target"] */
|
|
49
|
+
ESBUILD_BROWSER_TARGET: ["chrome130", "edge130", "firefox130", "safari18"]
|
|
50
|
+
//...
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Dependency updates: `fastify@5.7.2`, `@fastify/multipart@9.4.0`
|
|
55
|
+
|
|
56
|
+
## 2026-01-17 - Jeasx 2.2.2 released
|
|
57
|
+
|
|
58
|
+
🎉 This release now preserves the original status code when a 404 page is accessed directly (defaults 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.
|
|
59
|
+
|
|
60
|
+
While Jeasx is fundamentally a server-side rendering framework, there are valid use cases where serving a static page alone is sufficient. For example, you can use `wget` to download a Jeasx website to a www-directory with just a single line:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
wget --mirror --page-requisites --no-host-directories --directory-prefix=www http://localhost:3000 http://localhost:3000/404
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
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.
|
|
67
|
+
|
|
68
|
+
If you want to restore the old behaviour (directly calling /404 resulting in status code 404), you can simple add `reply.status(404)` to your `/[404]` handler.
|
|
69
|
+
|
|
70
|
+
Dependency updates: `fastify@5.7.1`, `@fastify/static@9.0.0`, `@types/node@24.10.9`
|
|
71
|
+
|
|
3
72
|
## 2025-12-21 - Jeasx 2.2.1 released
|
|
4
73
|
|
|
5
74
|
🎉 Just a patch release with a minor cleanup for explicit path joins in `serverless.ts`.
|
|
@@ -10,15 +79,15 @@ Dependency updates: `esbuild@0.27.2`, `jsx-async-runtime@2.0.2`, `@types/node@24
|
|
|
10
79
|
|
|
11
80
|
🎉 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.
|
|
12
81
|
|
|
13
|
-
**Breaking change**: The previously supported environment variables (
|
|
82
|
+
**Breaking change**: The previously supported environment variables (`FASTIFY_BODY_LIMIT, FASTIFY_DISABLE_REQUEST_LOGGING, FASTIFY_REWRITE_URL, FASTIFY_STATIC_HEADERS, FASTIFY_TRUST_PROXY, FASTIFY_MULTIPART_ATTACH_FIELDS_TO_BODY`) have been completely removed. While this may seem inconvenient for a minor release, the process of migrating your setup to the new configuration approach usually takes less than a minute. This streamlines the code base and documentation, as these features are presumably seldom used.
|
|
14
83
|
|
|
15
84
|
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:
|
|
16
85
|
|
|
17
|
-
- [`FASTIFY_SERVER_OPTIONS`](
|
|
18
|
-
- [`FASTIFY_COOKIE_OPTIONS`](
|
|
19
|
-
- [`FASTIFY_FORMBODY_OPTIONS`](
|
|
20
|
-
- [`FASTIFY_MULTIPART_OPTIONS`](
|
|
21
|
-
- [`FASTIFY_STATIC_OPTIONS`](
|
|
86
|
+
- [`FASTIFY_SERVER_OPTIONS`](https://fastify.dev/docs/latest/Reference/Server/)
|
|
87
|
+
- [`FASTIFY_COOKIE_OPTIONS`](https://github.com/fastify/fastify-cookie#options)
|
|
88
|
+
- [`FASTIFY_FORMBODY_OPTIONS`](https://github.com/fastify/fastify-formbody#options)
|
|
89
|
+
- [`FASTIFY_MULTIPART_OPTIONS`](https://github.com/fastify/fastify-multipart#options)
|
|
90
|
+
- [`FASTIFY_STATIC_OPTIONS`](https://github.com/fastify/fastify-static#options)
|
|
22
91
|
|
|
23
92
|
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.
|
|
24
93
|
|
|
@@ -59,7 +128,7 @@ Dependency updates: `@types/node@24.10.1`
|
|
|
59
128
|
|
|
60
129
|
## 2025-11-10 - Jeasx 2.1.1 released
|
|
61
130
|
|
|
62
|
-
🎉 Enhanced configuration for @fastify/static, so you can serve pre-compressed static files (see
|
|
131
|
+
🎉 Enhanced configuration for @fastify/static, so you can serve pre-compressed static files (see [fastify docs](https://github.com/fastify/fastify-static?tab=readme-ov-file#precompressed)) from `public` and `dist/browser`. Just run `gzip -rk public dist/browser` as post build for gzipping your static assets. This might be useful if you don't want to run a reverse proxy in front of your Jeasx application and serve compressed files nevertheless. Setting up compression for dynamic content can be wired up in userland via a root guard:
|
|
63
132
|
|
|
64
133
|
```js
|
|
65
134
|
import { promisify } from "node:util";
|
|
@@ -329,7 +398,7 @@ Added two new environment variables (`FASTIFY_DISABLE_REQUEST_LOGGING` and `FAST
|
|
|
329
398
|
|
|
330
399
|
## 2024-12-01 - Jeasx 1.1.0 released
|
|
331
400
|
|
|
332
|
-
🎉 Migrated from dotenv to dotenv-flow, so you can use NODE_ENV-specific .env
|
|
401
|
+
🎉 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.
|
|
333
402
|
|
|
334
403
|
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.
|
|
335
404
|
|
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/env.js
CHANGED
|
@@ -2,8 +2,7 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Load environment variables from .env
|
|
6
|
-
* into process.env in the following order:
|
|
5
|
+
* Load environment variables from .env-files into process.env in the following order:
|
|
7
6
|
*
|
|
8
7
|
* 1. .env.<NODE_ENV>.local
|
|
9
8
|
* 2. .env.<NODE_ENV>
|
|
@@ -12,47 +11,36 @@ import { join } from "node:path";
|
|
|
12
11
|
* 5. .env.defaults
|
|
13
12
|
* 6. .env.js
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
* it will be not overwritten at a later stage.
|
|
14
|
+
* .env.js is imported as an ES module and will always overwrite existing variables.
|
|
17
15
|
*/
|
|
18
16
|
export default async function env() {
|
|
19
17
|
if (process.loadEnvFile) {
|
|
20
18
|
[
|
|
21
|
-
...(process.env.NODE_ENV
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
...(process.env.NODE_ENV ?
|
|
20
|
+
[`.env.${process.env.NODE_ENV}.local`, `.env.${process.env.NODE_ENV}`]
|
|
21
|
+
: []),
|
|
24
22
|
".env.local",
|
|
25
23
|
".env",
|
|
26
|
-
".env.defaults"
|
|
24
|
+
".env.defaults"
|
|
27
25
|
]
|
|
28
26
|
.filter(existsSync)
|
|
29
27
|
.forEach(process.loadEnvFile);
|
|
30
28
|
}
|
|
31
29
|
try {
|
|
32
30
|
const envFile = `file://${join(process.cwd(), ".env.js")}`;
|
|
33
|
-
const envObject =
|
|
34
|
-
Object.entries(envObject)
|
|
35
|
-
|
|
36
|
-
.forEach(([key, value]) => {
|
|
31
|
+
const envObject = (await import(envFile)).default;
|
|
32
|
+
Object.entries(envObject).forEach(([key, value]) => {
|
|
33
|
+
try {
|
|
37
34
|
process.env[key] =
|
|
38
35
|
typeof value === "string" ? value : JSON.stringify(value);
|
|
39
|
-
})
|
|
40
|
-
|
|
36
|
+
} catch (error) {
|
|
37
|
+
// JSON.stringify throws TypeError for circular references or BigInts.
|
|
38
|
+
console.error("❌", `"${key}" in .env.js throws`, error);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return { ...process.env, ...envObject };
|
|
42
|
+
} catch {
|
|
41
43
|
// ERR_MODULE_NOT_FOUND
|
|
44
|
+
return { ...process.env };
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Convert all functions recursively to strings.
|
|
47
|
-
*/
|
|
48
|
-
function stringifyFunctions(obj) {
|
|
49
|
-
for (const key in obj) {
|
|
50
|
-
if (typeof obj[key] === "function") {
|
|
51
|
-
obj[key] = obj[key].toString();
|
|
52
|
-
}
|
|
53
|
-
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
54
|
-
stringifyFunctions(obj[key]);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return obj;
|
|
58
|
-
}
|
package/esbuild.config.js
CHANGED
|
@@ -1,35 +1,49 @@
|
|
|
1
|
+
import mdx from "@mdx-js/esbuild";
|
|
1
2
|
import * as esbuild from "esbuild";
|
|
2
3
|
import env from "./env.js";
|
|
3
4
|
|
|
4
|
-
await env();
|
|
5
|
+
const ENV = await env();
|
|
5
6
|
|
|
6
|
-
const BUILD_TIME = `"${Date.now().toString(36)}"`;
|
|
7
|
+
const BUILD_TIME = `"${ENV.BUILD_TIME || Date.now().toString(36)}"`;
|
|
7
8
|
|
|
8
|
-
const BROWSER_PUBLIC_ENV = Object.keys(
|
|
9
|
+
const BROWSER_PUBLIC_ENV = Object.keys(ENV)
|
|
9
10
|
.filter((key) => key.startsWith("BROWSER_PUBLIC_"))
|
|
10
11
|
.reduce(
|
|
11
12
|
(env, key) => {
|
|
12
|
-
env[`process.env.${key}`] = `"${
|
|
13
|
+
env[`process.env.${key}`] = `"${ENV[key]}"`;
|
|
13
14
|
return env;
|
|
14
15
|
},
|
|
15
16
|
{ "process.env.BROWSER_PUBLIC_BUILD_TIME": BUILD_TIME }
|
|
16
17
|
);
|
|
17
18
|
|
|
18
|
-
const ESBUILD_BROWSER_TARGET =
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const ESBUILD_BROWSER_TARGET = ENV.ESBUILD_BROWSER_TARGET || [
|
|
20
|
+
"chrome130",
|
|
21
|
+
"edge130",
|
|
22
|
+
"firefox130",
|
|
23
|
+
"safari18"
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const ESBUILD_MDX_PLUGIN = mdx({
|
|
27
|
+
development: process.env.NODE_ENV === "development",
|
|
28
|
+
jsxImportSource: "jsx-async-runtime",
|
|
29
|
+
elementAttributeNameCase: "html",
|
|
30
|
+
stylePropertyNameCase: "css",
|
|
31
|
+
...(ENV.ESBUILD_MDX_OPTIONS || {})
|
|
32
|
+
});
|
|
21
33
|
|
|
22
34
|
/** @type esbuild.BuildOptions[] */
|
|
23
35
|
const buildOptions = [
|
|
24
36
|
{
|
|
25
|
-
entryPoints: ["js", "ts", "jsx", "tsx"].map(
|
|
37
|
+
entryPoints: ["js", "ts", "jsx", "tsx", "mdx"].map(
|
|
38
|
+
(ext) => `src/**/[*].${ext}`
|
|
39
|
+
),
|
|
26
40
|
define: {
|
|
27
|
-
"process.env.BUILD_TIME": BUILD_TIME
|
|
41
|
+
"process.env.BUILD_TIME": BUILD_TIME
|
|
28
42
|
},
|
|
29
43
|
minify: process.env.NODE_ENV !== "development",
|
|
30
44
|
logLevel: "info",
|
|
31
45
|
logOverride: {
|
|
32
|
-
"empty-glob": "silent"
|
|
46
|
+
"empty-glob": "silent"
|
|
33
47
|
},
|
|
34
48
|
color: true,
|
|
35
49
|
bundle: true,
|
|
@@ -38,6 +52,7 @@ const buildOptions = [
|
|
|
38
52
|
outdir: "dist/server",
|
|
39
53
|
platform: "neutral",
|
|
40
54
|
packages: "external",
|
|
55
|
+
plugins: [ESBUILD_MDX_PLUGIN]
|
|
41
56
|
},
|
|
42
57
|
{
|
|
43
58
|
entryPoints: ["js", "ts", "jsx", "tsx", "css"].map(
|
|
@@ -47,7 +62,7 @@ const buildOptions = [
|
|
|
47
62
|
minify: process.env.NODE_ENV !== "development",
|
|
48
63
|
logLevel: "info",
|
|
49
64
|
logOverride: {
|
|
50
|
-
"empty-glob": "silent"
|
|
65
|
+
"empty-glob": "silent"
|
|
51
66
|
},
|
|
52
67
|
color: true,
|
|
53
68
|
bundle: true,
|
|
@@ -69,9 +84,10 @@ const buildOptions = [
|
|
|
69
84
|
"*.ttf",
|
|
70
85
|
"*.otf",
|
|
71
86
|
"*.woff",
|
|
72
|
-
"*.woff2"
|
|
87
|
+
"*.woff2"
|
|
73
88
|
],
|
|
74
|
-
|
|
89
|
+
plugins: [ESBUILD_MDX_PLUGIN]
|
|
90
|
+
}
|
|
75
91
|
];
|
|
76
92
|
|
|
77
93
|
buildOptions.forEach(async (options) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jeasx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Jeasx - the ease of JSX with the power of SSR",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsx",
|
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@fastify/cookie": "11.0.2",
|
|
28
28
|
"@fastify/formbody": "8.0.2",
|
|
29
|
-
"@fastify/multipart": "9.
|
|
30
|
-
"@fastify/static": "
|
|
31
|
-
"@
|
|
29
|
+
"@fastify/multipart": "9.4.0",
|
|
30
|
+
"@fastify/static": "9.0.0",
|
|
31
|
+
"@mdx-js/esbuild": "3.1.1",
|
|
32
|
+
"@types/node": "24.10.9",
|
|
32
33
|
"esbuild": "0.27.2",
|
|
33
|
-
"fastify": "5.
|
|
34
|
+
"fastify": "5.7.2",
|
|
34
35
|
"jsx-async-runtime": "2.0.2"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
package/server.js
CHANGED
package/serverless.js
CHANGED
|
@@ -8,36 +8,26 @@ import { stat } from "node:fs/promises";
|
|
|
8
8
|
import { freemem } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import env from "./env.js";
|
|
11
|
-
await env();
|
|
11
|
+
const ENV = await env();
|
|
12
12
|
const CWD = process.cwd();
|
|
13
13
|
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
|
-
...
|
|
18
|
-
process.env.FASTIFY_SERVER_OPTIONS
|
|
19
|
-
)
|
|
17
|
+
...ENV.FASTIFY_SERVER_OPTIONS || {}
|
|
20
18
|
}).register(fastifyCookie, {
|
|
21
|
-
...
|
|
22
|
-
process.env.FASTIFY_COOKIE_OPTIONS
|
|
23
|
-
)
|
|
19
|
+
...ENV.FASTIFY_COOKIE_OPTIONS || {}
|
|
24
20
|
}).register(fastifyFormbody, {
|
|
25
|
-
...
|
|
26
|
-
process.env.FASTIFY_FORMBODY_OPTIONS
|
|
27
|
-
)
|
|
21
|
+
...ENV.FASTIFY_FORMBODY_OPTIONS || {}
|
|
28
22
|
}).register(fastifyMultipart, {
|
|
29
23
|
attachFieldsToBody: "keyValues",
|
|
30
|
-
...
|
|
31
|
-
process.env.FASTIFY_MULTIPART_OPTIONS
|
|
32
|
-
)
|
|
24
|
+
...ENV.FASTIFY_MULTIPART_OPTIONS || {}
|
|
33
25
|
}).register(fastifyStatic, {
|
|
34
26
|
root: [["public"], ["dist", "browser"]].map((dir) => join(CWD, ...dir)),
|
|
35
27
|
prefix: "/",
|
|
36
28
|
wildcard: false,
|
|
37
29
|
preCompressed: true,
|
|
38
|
-
...
|
|
39
|
-
process.env.FASTIFY_STATIC_OPTIONS
|
|
40
|
-
)
|
|
30
|
+
...ENV.FASTIFY_STATIC_OPTIONS || {}
|
|
41
31
|
}).decorateRequest("route", "").decorateRequest("path", "").addHook("onRequest", async (request, reply) => {
|
|
42
32
|
reply.header("Content-Type", "text/html; charset=utf-8");
|
|
43
33
|
const index = request.url.indexOf("?");
|
|
@@ -50,19 +40,6 @@ var serverless_default = Fastify({
|
|
|
50
40
|
throw error;
|
|
51
41
|
}
|
|
52
42
|
});
|
|
53
|
-
function jsonToOptions(json) {
|
|
54
|
-
const options = JSON.parse(json || "{}");
|
|
55
|
-
for (const key in options) {
|
|
56
|
-
if (typeof options[key] === "string" && options[key].includes("=>")) {
|
|
57
|
-
try {
|
|
58
|
-
options[key] = new Function(`return ${options[key]}`)();
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.warn("\u26A0\uFE0F", error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return options;
|
|
65
|
-
}
|
|
66
43
|
const modules = /* @__PURE__ */ new Map();
|
|
67
44
|
async function handler(request, reply) {
|
|
68
45
|
let response;
|
|
@@ -110,7 +87,9 @@ async function handler(request, reply) {
|
|
|
110
87
|
if (reply.sent) {
|
|
111
88
|
return;
|
|
112
89
|
} else if (route.endsWith("/[404]")) {
|
|
113
|
-
reply.
|
|
90
|
+
if (reply.statusCode === 200 && !request.path.endsWith("/404")) {
|
|
91
|
+
reply.status(404);
|
|
92
|
+
}
|
|
114
93
|
break;
|
|
115
94
|
} else if (typeof response === "string" || Buffer.isBuffer(response) || isJSX(response)) {
|
|
116
95
|
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;
|
|
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,MAAM,MAAM,IAAI;AAEtB,MAAM,MAAM,QAAQ,IAAI;AACxB,MAAM,0BAA0B,QAAQ,IAAI,aAAa;AACzD,MAA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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";
|
|
@@ -13,7 +13,7 @@ import { freemem } from "node:os";
|
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
import env from "./env.js";
|
|
15
15
|
|
|
16
|
-
await env();
|
|
16
|
+
const ENV = await env();
|
|
17
17
|
|
|
18
18
|
const CWD = process.cwd();
|
|
19
19
|
const NODE_ENV_IS_DEVELOPMENT = process.env.NODE_ENV === "development";
|
|
@@ -29,34 +29,24 @@ declare module "fastify" {
|
|
|
29
29
|
// Create and export a Fastify app instance
|
|
30
30
|
export default Fastify({
|
|
31
31
|
logger: true,
|
|
32
|
-
...(
|
|
33
|
-
process.env.FASTIFY_SERVER_OPTIONS
|
|
34
|
-
) as FastifyServerOptions),
|
|
32
|
+
...((ENV.FASTIFY_SERVER_OPTIONS || {}) as FastifyServerOptions)
|
|
35
33
|
})
|
|
36
34
|
.register(fastifyCookie, {
|
|
37
|
-
...(
|
|
38
|
-
process.env.FASTIFY_COOKIE_OPTIONS
|
|
39
|
-
) as FastifyCookieOptions),
|
|
35
|
+
...((ENV.FASTIFY_COOKIE_OPTIONS || {}) as FastifyCookieOptions)
|
|
40
36
|
})
|
|
41
37
|
.register(fastifyFormbody, {
|
|
42
|
-
...(
|
|
43
|
-
process.env.FASTIFY_FORMBODY_OPTIONS
|
|
44
|
-
) as FastifyFormbodyOptions),
|
|
38
|
+
...((ENV.FASTIFY_FORMBODY_OPTIONS || {}) as FastifyFormbodyOptions)
|
|
45
39
|
})
|
|
46
40
|
.register(fastifyMultipart, {
|
|
47
41
|
attachFieldsToBody: "keyValues",
|
|
48
|
-
...(
|
|
49
|
-
process.env.FASTIFY_MULTIPART_OPTIONS
|
|
50
|
-
) as FastifyMultipartOptions),
|
|
42
|
+
...((ENV.FASTIFY_MULTIPART_OPTIONS || {}) as FastifyMultipartOptions)
|
|
51
43
|
})
|
|
52
44
|
.register(fastifyStatic, {
|
|
53
45
|
root: [["public"], ["dist", "browser"]].map((dir) => join(CWD, ...dir)),
|
|
54
46
|
prefix: "/",
|
|
55
47
|
wildcard: false,
|
|
56
48
|
preCompressed: true,
|
|
57
|
-
...(
|
|
58
|
-
process.env.FASTIFY_STATIC_OPTIONS
|
|
59
|
-
) as FastifyStaticOptions),
|
|
49
|
+
...((ENV.FASTIFY_STATIC_OPTIONS || {}) as FastifyStaticOptions)
|
|
60
50
|
})
|
|
61
51
|
.decorateRequest("route", "")
|
|
62
52
|
.decorateRequest("path", "")
|
|
@@ -76,23 +66,6 @@ export default Fastify({
|
|
|
76
66
|
}
|
|
77
67
|
});
|
|
78
68
|
|
|
79
|
-
/**
|
|
80
|
-
* Parses JSON and instantiates all stringified functions.
|
|
81
|
-
*/
|
|
82
|
-
function jsonToOptions(json: string) {
|
|
83
|
-
const options = JSON.parse(json || "{}");
|
|
84
|
-
for (const key in options) {
|
|
85
|
-
if (typeof options[key] === "string" && options[key].includes("=>")) {
|
|
86
|
-
try {
|
|
87
|
-
options[key] = new Function(`return ${options[key]}`)();
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.warn("⚠️", error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return options;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
69
|
// Cache for resolved route modules, 'null' means no module exists.
|
|
97
70
|
const modules = new Map<string, { default: Function }>();
|
|
98
71
|
|
|
@@ -159,13 +132,17 @@ async function handler(request: FastifyRequest, reply: FastifyReply) {
|
|
|
159
132
|
response = await module.default.call(context, {
|
|
160
133
|
request,
|
|
161
134
|
reply,
|
|
162
|
-
...(typeof response === "object" ? response : {})
|
|
135
|
+
...(typeof response === "object" ? response : {})
|
|
163
136
|
});
|
|
164
137
|
|
|
165
138
|
if (reply.sent) {
|
|
166
139
|
return;
|
|
167
140
|
} else if (route.endsWith("/[404]")) {
|
|
168
|
-
|
|
141
|
+
// Preserve existing status if a 404 page is requested directly.
|
|
142
|
+
// If no status is defined, set status to 404 automatically.
|
|
143
|
+
if (reply.statusCode === 200 && !request.path.endsWith("/404")) {
|
|
144
|
+
reply.status(404);
|
|
145
|
+
}
|
|
169
146
|
break;
|
|
170
147
|
} else if (
|
|
171
148
|
typeof response === "string" ||
|
|
@@ -213,7 +190,7 @@ function generateRoutes(path: string): string[] {
|
|
|
213
190
|
.map((segment) => `${segment}/[...guard]`),
|
|
214
191
|
...edges.map((edge) => `${edge}`),
|
|
215
192
|
...segments.map((segment) => `${segment}/[...path]`),
|
|
216
|
-
...segments.map((segment) => `${segment}/[404]`)
|
|
193
|
+
...segments.map((segment) => `${segment}/[404]`)
|
|
217
194
|
];
|
|
218
195
|
}
|
|
219
196
|
|
|
@@ -264,13 +241,12 @@ function isJSX(obj: unknown): boolean {
|
|
|
264
241
|
* Renders JSX to string and applies optional response handler.
|
|
265
242
|
*/
|
|
266
243
|
async function renderJSX(context: object, response: unknown) {
|
|
267
|
-
const payload =
|
|
268
|
-
? await jsxToString.call(context, response)
|
|
269
|
-
: response;
|
|
244
|
+
const payload =
|
|
245
|
+
isJSX(response) ? await jsxToString.call(context, response) : response;
|
|
270
246
|
|
|
271
247
|
// Post-process the payload with an optional response handler
|
|
272
248
|
const responseHandler = context["responseHandler"];
|
|
273
|
-
return typeof responseHandler === "function"
|
|
274
|
-
|
|
249
|
+
return typeof responseHandler === "function" ?
|
|
250
|
+
await responseHandler.call(context, payload)
|
|
275
251
|
: payload;
|
|
276
252
|
}
|