@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.
Files changed (3) hide show
  1. package/README.md +17 -14
  2. package/dist/index.js +26 -24
  3. package/package.json +6 -6
package/README.md CHANGED
@@ -1,17 +1,20 @@
1
1
  # Cossack Framework Node Adapter
2
2
 
3
- This package provides a Node.js adapter for the Cossack Framework, allowing you to run your Cossack applications in a Node.js environment. It includes utilities for handling HTTP requests and responses, WebSocket upgrades, static file serving, and runtime polyfills that keep application code identical across Cloudflare Workers and Node.js.
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
- Refer to our [Installation Guide](https://cossack.dev/docs/installation) for detailed instructions on how to set up the Cossack Framework and its packages.
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` — handles WebSocket upgrades and component bootstrapping on a Node `http.Server`.
11
- - `nodeRuntimeAdapter` — pass to `createApp()` so SSR emits Node process-local WebSocket targets.
12
- - `serveStatic` — Node `fs`-based Hono middleware for serving static assets.
13
- - `NodeWebSocketRuntime` — the WebSocket runtime used by the adapter.
14
- - `createNodeEmailSender` — Node.js polyfill for Cloudflare's `send_email` binding (`env.EMAIL`).
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 | Description | Default |
80
+ | Variable | Description | Default |
78
81
  | -------------- | -------------------------------------------- | ------------------ |
79
- | `SMTP_HOST` | SMTP server host (e.g. `smtp.gmail.com`) | — |
80
- | `SMTP_PORT` | SMTP server port | `587` |
81
- | `SMTP_SECURE` | Use TLS (`"true"` for port 465) | `port === 465` |
82
- | `SMTP_USER` | SMTP username | — |
83
- | `SMTP_PASS` | SMTP password | — |
84
- | `MAIL_FROM` | Default `from` address when omitted | `no-reply@example.com` |
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, a) => {
39
- if (e.req.method !== "GET" && e.req.method !== "HEAD") return a();
40
- let c = u(e.req.path);
41
- if (!c.startsWith(n)) return a();
42
- let d = c.substring(n.length);
43
- d === "" && (d = "/");
44
- let p;
45
- if (d === "/") {
46
- if (!r) return a();
47
- p = s.join(t, "index.html");
48
- } else if (p = s.join(t, d), r && !o.existsSync(p)) {
49
- let e = s.join(p, "index.html");
50
- o.existsSync(e) && (p = 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(p)) return a();
52
+ if (!l(m)) return c();
53
53
  try {
54
- let e = await o.promises.stat(p);
55
- if (e.isDirectory()) if (r) {
56
- let t = s.join(p, "index.html");
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(t), p = t, e = await o.promises.stat(p);
58
+ await o.promises.access(e), m = e, t = await o.promises.stat(m);
59
59
  } catch {
60
- return a();
60
+ return c();
61
61
  }
62
- } else return a();
63
- let t = await o.promises.readFile(p), n = f(p), l = new Headers({ "Content-Type": n }), u = typeof i == "function" ? i(p, c) : i;
64
- return u && l.set("Cache-Control", u), new Response(new Uint8Array(t), {
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: l
68
+ headers: g
67
69
  });
68
70
  } catch {
69
- return a();
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.2",
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": "^9.0.3",
28
+ "nodemailer": "^10.0.6",
29
29
  "ws": ">=8.21.0",
30
- "@cossackframework/core": "0.8.2"
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.12.34",
35
+ "hono": "^4.13.7",
36
36
  "typescript": "^7.0.2",
37
37
  "vite": "^8.1.4",
38
- "vitest": "^4.1.10"
38
+ "vitest": "^4.1.11"
39
39
  },
40
40
  "peerDependencies": {
41
- "hono": "^4.12.34"
41
+ "hono": "^4.13.7"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "vite build && tsc -p tsconfig.declarations.json",