@cossackframework/node-adapter 0.8.2 → 0.8.3
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/README.md +17 -14
- package/dist/index.js +26 -24
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
# Cossack Framework Node Adapter
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package runs Cossack applications on Node.js. It handles HTTP requests,
|
|
4
|
+
WebSocket upgrades, and static files. It also provides runtime polyfills so
|
|
5
|
+
application code can work on Cloudflare Workers and Node.js.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
|
-
|
|
8
|
+
See the [Installation Guide](https://cossack.dev/docs/installation) to set up
|
|
9
|
+
Cossack and its packages.
|
|
7
10
|
|
|
8
11
|
## Exports
|
|
9
12
|
|
|
10
|
-
- `CossackNodeAdapter`
|
|
11
|
-
- `nodeRuntimeAdapter`
|
|
12
|
-
- `serveStatic`
|
|
13
|
-
- `NodeWebSocketRuntime`
|
|
14
|
-
- `createNodeEmailSender`
|
|
13
|
+
- `CossackNodeAdapter` : handles WebSocket upgrades and component bootstrapping on a Node `http.Server`.
|
|
14
|
+
- `nodeRuntimeAdapter` : pass to `createApp()` so SSR emits Node process-local WebSocket targets.
|
|
15
|
+
- `serveStatic` : Node `fs`-based Hono middleware for serving static assets.
|
|
16
|
+
- `NodeWebSocketRuntime` : the WebSocket runtime used by the adapter.
|
|
17
|
+
- `createNodeEmailSender` : Node.js polyfill for Cloudflare's `send_email` binding (`env.EMAIL`).
|
|
15
18
|
|
|
16
19
|
## Unified `env.EMAIL` (Cloudflare email binding polyfill)
|
|
17
20
|
|
|
@@ -74,13 +77,13 @@ new CossackNodeAdapter({
|
|
|
74
77
|
### Environment variables
|
|
75
78
|
Configure via `.dev.vars` (Cloudflare dev) or your shell/`.env` (Node):
|
|
76
79
|
|
|
77
|
-
| Variable
|
|
80
|
+
| Variable | Description | Default |
|
|
78
81
|
| -------------- | -------------------------------------------- | ------------------ |
|
|
79
|
-
| `SMTP_HOST`
|
|
80
|
-
| `SMTP_PORT`
|
|
81
|
-
| `SMTP_SECURE`
|
|
82
|
-
| `SMTP_USER`
|
|
83
|
-
| `SMTP_PASS`
|
|
84
|
-
| `MAIL_FROM`
|
|
82
|
+
| `SMTP_HOST` | SMTP server host (e.g. `smtp.gmail.com`) | : |
|
|
83
|
+
| `SMTP_PORT` | SMTP server port | `587` |
|
|
84
|
+
| `SMTP_SECURE` | Use TLS (`"true"` for port 465) | `port === 465` |
|
|
85
|
+
| `SMTP_USER` | SMTP username | : |
|
|
86
|
+
| `SMTP_PASS` | SMTP password | : |
|
|
87
|
+
| `MAIL_FROM` | Default `from` address when omitted | `no-reply@example.com` |
|
|
85
88
|
|
|
86
89
|
Now `await this.env.EMAIL.send(...)` works identically in `@Server` methods on both Cloudflare Workers and Node.js.
|
package/dist/index.js
CHANGED
|
@@ -35,38 +35,40 @@ function d(e) {
|
|
|
35
35
|
let t = s.resolve(e);
|
|
36
36
|
return t === a || t.startsWith(c);
|
|
37
37
|
};
|
|
38
|
-
return async (e,
|
|
39
|
-
if (e.req.method !== "GET" && e.req.method !== "HEAD") return
|
|
40
|
-
let
|
|
41
|
-
if (!
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
let
|
|
45
|
-
if (
|
|
46
|
-
if (!r) return
|
|
47
|
-
|
|
48
|
-
} else if (
|
|
49
|
-
let e = s.join(
|
|
50
|
-
o.existsSync(e) && (
|
|
38
|
+
return async (e, c) => {
|
|
39
|
+
if (e.req.method !== "GET" && e.req.method !== "HEAD") return c();
|
|
40
|
+
let d = u(e.req.path);
|
|
41
|
+
if (!d.startsWith(n)) return c();
|
|
42
|
+
let p = d.substring(n.length);
|
|
43
|
+
p === "" && (p = "/");
|
|
44
|
+
let m;
|
|
45
|
+
if (p === "/") {
|
|
46
|
+
if (!r) return c();
|
|
47
|
+
m = s.join(t, "index.html");
|
|
48
|
+
} else if (m = s.join(t, p), r && !o.existsSync(m)) {
|
|
49
|
+
let e = s.join(m, "index.html");
|
|
50
|
+
o.existsSync(e) && (m = e);
|
|
51
51
|
}
|
|
52
|
-
if (!l(
|
|
52
|
+
if (!l(m)) return c();
|
|
53
53
|
try {
|
|
54
|
-
let
|
|
55
|
-
if (
|
|
56
|
-
let
|
|
54
|
+
let t = await o.promises.stat(m);
|
|
55
|
+
if (t.isDirectory()) if (r) {
|
|
56
|
+
let e = s.join(m, "index.html");
|
|
57
57
|
try {
|
|
58
|
-
await o.promises.access(
|
|
58
|
+
await o.promises.access(e), m = e, t = await o.promises.stat(m);
|
|
59
59
|
} catch {
|
|
60
|
-
return
|
|
60
|
+
return c();
|
|
61
61
|
}
|
|
62
|
-
} else return
|
|
63
|
-
let
|
|
64
|
-
|
|
62
|
+
} else return c();
|
|
63
|
+
let [n, l] = await Promise.all([o.promises.realpath(a), o.promises.realpath(m)]), u = s.relative(n, l);
|
|
64
|
+
if (u === ".." || u.startsWith(`..${s.sep}`) || s.isAbsolute(u) || !t.isFile()) return c();
|
|
65
|
+
let p = e.req.method === "HEAD" ? null : await o.promises.readFile(l), h = f(m), g = new Headers({ "Content-Type": h }), _ = typeof i == "function" ? i(m, d) : i;
|
|
66
|
+
return _ && g.set("Cache-Control", _), new Response(p === null ? null : new Uint8Array(p), {
|
|
65
67
|
status: 200,
|
|
66
|
-
headers:
|
|
68
|
+
headers: g
|
|
67
69
|
});
|
|
68
70
|
} catch {
|
|
69
|
-
return
|
|
71
|
+
return c();
|
|
70
72
|
}
|
|
71
73
|
};
|
|
72
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cossackframework/node-adapter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Node.js runtime adapter for the Cossack Framework",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,20 +25,20 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"nodemailer": "^
|
|
28
|
+
"nodemailer": "^10.0.6",
|
|
29
29
|
"ws": ">=8.21.0",
|
|
30
|
-
"@cossackframework/core": "0.8.
|
|
30
|
+
"@cossackframework/core": "0.8.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/nodemailer": "^8.0.1",
|
|
34
34
|
"@types/ws": "^8.18.0",
|
|
35
|
-
"hono": "^4.
|
|
35
|
+
"hono": "^4.13.7",
|
|
36
36
|
"typescript": "^7.0.2",
|
|
37
37
|
"vite": "^8.1.4",
|
|
38
|
-
"vitest": "^4.1.
|
|
38
|
+
"vitest": "^4.1.11"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"hono": "^4.
|
|
41
|
+
"hono": "^4.13.7"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "vite build && tsc -p tsconfig.declarations.json",
|