@rudderjs/server-hono 0.0.6
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/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/error-page.d.ts +6 -0
- package/dist/error-page.d.ts.map +1 -0
- package/dist/error-page.js +190 -0
- package/dist/error-page.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +330 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Suleiman Shahbari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @rudderjs/server-hono
|
|
2
|
+
|
|
3
|
+
Hono-based HTTP server adapter for RudderJS. Implements the `ServerAdapterProvider` contract and wires up routing, middleware, CORS, request logging, and the Vike SSR fetch handler.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @rudderjs/server-hono
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// bootstrap/app.ts
|
|
15
|
+
import { Application } from '@rudderjs/core'
|
|
16
|
+
import { hono } from '@rudderjs/server-hono'
|
|
17
|
+
import configs from '../config/index.js'
|
|
18
|
+
import providers from './providers.js'
|
|
19
|
+
|
|
20
|
+
export default Application.configure({
|
|
21
|
+
server: hono(configs.server),
|
|
22
|
+
config: configs,
|
|
23
|
+
providers,
|
|
24
|
+
})
|
|
25
|
+
.withRouting({
|
|
26
|
+
api: () => import('../routes/api.js'),
|
|
27
|
+
commands: () => import('../routes/console.js'),
|
|
28
|
+
})
|
|
29
|
+
.create()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Typical `config/server.ts`:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Env } from '@rudderjs/support'
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
port: Env.getNumber('PORT', 3000),
|
|
39
|
+
trustProxy: Env.getBool('TRUST_PROXY', false),
|
|
40
|
+
cors: {
|
|
41
|
+
origin: Env.get('CORS_ORIGIN', '*'),
|
|
42
|
+
methods: Env.get('CORS_METHODS', 'GET,POST,PUT,PATCH,DELETE,OPTIONS'),
|
|
43
|
+
headers: Env.get('CORS_HEADERS', 'Content-Type,Authorization'),
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API Reference
|
|
49
|
+
|
|
50
|
+
### `hono(config?)`
|
|
51
|
+
|
|
52
|
+
Returns a `ServerAdapterProvider`. Options:
|
|
53
|
+
|
|
54
|
+
| Option | Type | Default | Description |
|
|
55
|
+
|--------|------|---------|-------------|
|
|
56
|
+
| `port` | `number` | `3000` | Port for `listen()` |
|
|
57
|
+
| `trustProxy` | `boolean` | `false` | Trust `X-Forwarded-*` proxy headers |
|
|
58
|
+
| `cors.origin` | `string` | `'*'` | Allowed CORS origin |
|
|
59
|
+
| `cors.methods` | `string` | `'GET,POST,PUT,PATCH,DELETE,OPTIONS'` | Allowed methods |
|
|
60
|
+
| `cors.headers` | `string` | `'Content-Type,Authorization'` | Allowed request headers |
|
|
61
|
+
|
|
62
|
+
The returned provider exposes:
|
|
63
|
+
|
|
64
|
+
| Method | Description |
|
|
65
|
+
|--------|-------------|
|
|
66
|
+
| `create()` | Returns a `ServerAdapter` instance |
|
|
67
|
+
| `createApp()` | Returns the underlying `Hono` app |
|
|
68
|
+
| `createFetchHandler(setup?)` | Returns a WinterCG-compatible `(Request) => Promise<Response>` handler |
|
|
69
|
+
|
|
70
|
+
## Built-in Features
|
|
71
|
+
|
|
72
|
+
### Request Logger
|
|
73
|
+
|
|
74
|
+
Logs every request in a single line — skips static assets and Vite internals. Vike client-side navigation requests (`pageContext.json`) are shown as clean page paths with a `↩ nav` suffix:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
01:01:20 #1 / .................................................. ~216ms 200
|
|
78
|
+
01:01:23 #2 /api/users .......................................... ~8.1ms 200
|
|
79
|
+
01:01:37 #3 /todos ↩ nav ........................................ ~5ms 200
|
|
80
|
+
01:01:42 #4 /api/contact ....................................... <1ms 429
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- Counter (`#N`) — request sequence number
|
|
84
|
+
- Dots fill the space so the duration and status always align
|
|
85
|
+
- Duration — `<1ms`, `~8.1ms`, `~216ms`, `~1.23s`
|
|
86
|
+
- Status color: 2xx → green, 3xx → cyan, 4xx → yellow, 5xx → red (24-bit truecolor, not affected by terminal themes)
|
|
87
|
+
|
|
88
|
+
### CORS
|
|
89
|
+
|
|
90
|
+
Configured via `HonoConfig.cors` — applied automatically before routes. No need to add `CorsMiddleware` manually.
|
|
91
|
+
|
|
92
|
+
### Dev Error Page
|
|
93
|
+
|
|
94
|
+
In non-production environments, unhandled errors render a styled HTML error page with the stack trace and source context.
|
|
95
|
+
|
|
96
|
+
## Notes
|
|
97
|
+
|
|
98
|
+
- `createFetchHandler()` is used by the Vike/Vite integration — not called directly
|
|
99
|
+
- CORS from `HonoConfig.cors` and `CorsMiddleware` from `@rudderjs/middleware` are independent — don't use both
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-page.d.ts","sourceRoot":"","sources":["../src/error-page.ts"],"names":[],"mappings":"AA4EA,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACpE,MAAM,CA4HR"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
function parseStack(stack) {
|
|
3
|
+
return stack.split('\n').slice(1).flatMap(raw => {
|
|
4
|
+
const m = raw.match(/^\s+at (.+?) \((.+?):(\d+):(\d+)\)$/)
|
|
5
|
+
?? raw.match(/^\s+at (.+?):(\d+):(\d+)$/);
|
|
6
|
+
if (!m)
|
|
7
|
+
return [];
|
|
8
|
+
const [func, file, line, col] = m.length === 5
|
|
9
|
+
? [m[1] ?? '', m[2] ?? '', m[3] ?? '', m[4] ?? '']
|
|
10
|
+
: ['<anonymous>', m[1] ?? '', m[2] ?? '', m[3] ?? ''];
|
|
11
|
+
const cleanFile = file.replace(/^file:\/\//, '');
|
|
12
|
+
return [{
|
|
13
|
+
func,
|
|
14
|
+
file: cleanFile,
|
|
15
|
+
line: parseInt(line),
|
|
16
|
+
col: parseInt(col),
|
|
17
|
+
isVendor: cleanFile.includes('node_modules'),
|
|
18
|
+
}];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* tsx source maps can report an off line number (e.g. an empty line).
|
|
23
|
+
* Scan forward from the reported line to find the actual throw/error statement.
|
|
24
|
+
*/
|
|
25
|
+
function resolveErrorLine(lines, reported) {
|
|
26
|
+
const reported0 = reported - 1; // 0-indexed
|
|
27
|
+
// If the reported line is non-empty, trust it
|
|
28
|
+
if (lines[reported0]?.trim())
|
|
29
|
+
return reported;
|
|
30
|
+
// Scan forward up to 20 lines for a throw statement
|
|
31
|
+
for (let i = reported0 + 1; i < Math.min(lines.length, reported0 + 20); i++) {
|
|
32
|
+
if (lines[i]?.trimStart().startsWith('throw '))
|
|
33
|
+
return i + 1;
|
|
34
|
+
}
|
|
35
|
+
// Fallback: first non-empty line
|
|
36
|
+
for (let i = reported0 + 1; i < Math.min(lines.length, reported0 + 20); i++) {
|
|
37
|
+
if (lines[i]?.trim())
|
|
38
|
+
return i + 1;
|
|
39
|
+
}
|
|
40
|
+
return reported;
|
|
41
|
+
}
|
|
42
|
+
function sourceContext(file, reportedLine) {
|
|
43
|
+
try {
|
|
44
|
+
const lines = fs.readFileSync(file, 'utf-8').split('\n');
|
|
45
|
+
const errorLine = resolveErrorLine(lines, reportedLine);
|
|
46
|
+
const start = Math.max(0, errorLine - 6);
|
|
47
|
+
const end = Math.min(lines.length, errorLine + 4);
|
|
48
|
+
return lines.slice(start, end).map((code, i) => ({
|
|
49
|
+
n: start + i + 1,
|
|
50
|
+
code,
|
|
51
|
+
isError: start + i + 1 === errorLine,
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function esc(s) {
|
|
59
|
+
return String(s)
|
|
60
|
+
.replace(/&/g, '&')
|
|
61
|
+
.replace(/</g, '<')
|
|
62
|
+
.replace(/>/g, '>')
|
|
63
|
+
.replace(/"/g, '"');
|
|
64
|
+
}
|
|
65
|
+
function rel(file) {
|
|
66
|
+
return file.replace(process.cwd() + '/', '').replace(process.env['HOME'] ?? '', '~');
|
|
67
|
+
}
|
|
68
|
+
export function renderErrorPage(error, req) {
|
|
69
|
+
const frames = parseStack(error.stack ?? '');
|
|
70
|
+
const appFrames = frames.filter(f => !f.isVendor);
|
|
71
|
+
const topFrame = appFrames[0] ?? frames[0];
|
|
72
|
+
const source = topFrame ? sourceContext(topFrame.file, topFrame.line) : null;
|
|
73
|
+
const vendorCount = frames.filter(f => f.isVendor).length;
|
|
74
|
+
const nodeVersion = process.version;
|
|
75
|
+
const rudderjsVersion = '0.0.2';
|
|
76
|
+
const frameRow = (f, isApp) => `
|
|
77
|
+
<div class="frame${isApp ? ' app' : ''}">
|
|
78
|
+
<span class="frame-func">${esc(f.func)}</span>
|
|
79
|
+
<span class="frame-file">${esc(rel(f.file))}:${f.line}</span>
|
|
80
|
+
</div>`;
|
|
81
|
+
return `<!DOCTYPE html>
|
|
82
|
+
<html lang="en">
|
|
83
|
+
<head>
|
|
84
|
+
<meta charset="UTF-8">
|
|
85
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
86
|
+
<title>${esc(error.name)} — RudderJS</title>
|
|
87
|
+
<style>
|
|
88
|
+
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
89
|
+
body{background:#0d0d0f;color:#d4d4d4;font-family:ui-sans-serif,system-ui,-apple-system,sans-serif;font-size:14px;line-height:1.6}
|
|
90
|
+
.top-bar{display:flex;align-items:center;gap:8px;padding:12px 24px;background:#18181b;border-bottom:1px solid #27272a;color:#ef4444;font-weight:600;font-size:13px}
|
|
91
|
+
.dot{width:8px;height:8px;background:#ef4444;border-radius:50%;flex-shrink:0}
|
|
92
|
+
.container{max-width:1100px;margin:0 auto;padding:40px 24px}
|
|
93
|
+
h1{font-size:28px;font-weight:700;color:#f4f4f5;margin-bottom:4px}
|
|
94
|
+
.location{font-size:13px;color:#71717a;margin-bottom:12px;font-family:ui-monospace,monospace}
|
|
95
|
+
.message{font-size:17px;color:#a1a1aa;margin-bottom:24px}
|
|
96
|
+
.badges{display:flex;gap:8px;margin-bottom:32px;flex-wrap:wrap}
|
|
97
|
+
.badge{padding:3px 10px;border-radius:4px;font-size:11px;font-weight:700;font-family:ui-monospace,monospace;letter-spacing:.04em}
|
|
98
|
+
.badge-gray{background:#27272a;color:#a1a1aa}
|
|
99
|
+
.badge-red{background:#450a0a;color:#f87171}
|
|
100
|
+
.request-bar{display:flex;align-items:center;gap:10px;background:#18181b;border:1px solid #27272a;border-radius:8px;padding:12px 16px;margin-bottom:36px}
|
|
101
|
+
.badge-orange{background:#422006;color:#fb923c}
|
|
102
|
+
.badge-status{background:#450a0a;color:#f87171;padding:3px 10px;border-radius:4px;font-size:11px;font-weight:700;font-family:ui-monospace,monospace}
|
|
103
|
+
.url{font-family:ui-monospace,monospace;color:#d4d4d4;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
104
|
+
.section{margin-bottom:32px}
|
|
105
|
+
.section-title{font-size:11px;font-weight:700;color:#71717a;text-transform:uppercase;letter-spacing:.08em;margin-bottom:10px}
|
|
106
|
+
.card{background:#18181b;border:1px solid #27272a;border-radius:8px;overflow:hidden}
|
|
107
|
+
.frame{padding:10px 16px;border-bottom:1px solid #27272a;display:flex;align-items:center;justify-content:space-between;gap:16px}
|
|
108
|
+
.frame:last-child{border-bottom:none}
|
|
109
|
+
.frame-func{font-family:ui-monospace,monospace;font-size:12px;color:#71717a;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
110
|
+
.frame-file{font-family:ui-monospace,monospace;font-size:12px;color:#52525b;flex-shrink:0}
|
|
111
|
+
.frame.app .frame-func{color:#e4e4e7}
|
|
112
|
+
.frame.app .frame-file{color:#60a5fa}
|
|
113
|
+
.vendor-toggle{color:#52525b;font-size:12px;cursor:pointer;padding:10px 16px;display:flex;align-items:center;justify-content:space-between;background:#18181b;border-top:1px solid #27272a}
|
|
114
|
+
.vendor-toggle:hover{color:#a1a1aa}
|
|
115
|
+
.vendor-frames{display:none}
|
|
116
|
+
.vendor-frames.open{display:block}
|
|
117
|
+
.code-block{font-family:ui-monospace,monospace;font-size:13px;line-height:1.8}
|
|
118
|
+
.code-line{display:flex}
|
|
119
|
+
.code-line-num{min-width:52px;padding:0 12px;color:#52525b;user-select:none;text-align:right;border-right:2px solid #27272a;flex-shrink:0}
|
|
120
|
+
.code-line-src{padding:0 16px;white-space:pre;color:#a1a1aa}
|
|
121
|
+
.code-line.error{background:#2d0a0a}
|
|
122
|
+
.code-line.error .code-line-num{color:#f87171;border-color:#ef4444}
|
|
123
|
+
.code-line.error .code-line-src{color:#fca5a5}
|
|
124
|
+
table{width:100%;border-collapse:collapse}
|
|
125
|
+
table tr{border-bottom:1px solid #27272a}
|
|
126
|
+
table tr:last-child{border-bottom:none}
|
|
127
|
+
table th{text-align:left;padding:8px 16px;color:#52525b;font-weight:500;width:200px;font-size:12px;font-family:ui-monospace,monospace}
|
|
128
|
+
table td{padding:8px 16px;font-family:ui-monospace,monospace;font-size:12px;color:#a1a1aa;word-break:break-all}
|
|
129
|
+
</style>
|
|
130
|
+
</head>
|
|
131
|
+
<body>
|
|
132
|
+
|
|
133
|
+
<div class="top-bar">
|
|
134
|
+
<div class="dot"></div>
|
|
135
|
+
Internal Server Error
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<div class="container">
|
|
139
|
+
<h1>${esc(error.name)}</h1>
|
|
140
|
+
${topFrame ? `<div class="location">${esc(rel(topFrame.file))}:${topFrame.line}</div>` : ''}
|
|
141
|
+
<div class="message">${esc(error.message)}</div>
|
|
142
|
+
|
|
143
|
+
<div class="badges">
|
|
144
|
+
<span class="badge badge-gray">NODE ${esc(nodeVersion)}</span>
|
|
145
|
+
<span class="badge badge-gray">RUDDERJS ${esc(rudderjsVersion)}</span>
|
|
146
|
+
<span class="badge badge-red">UNHANDLED</span>
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<div class="request-bar">
|
|
150
|
+
<span class="badge-status">500</span>
|
|
151
|
+
<span class="badge badge-orange">${esc(req.method)}</span>
|
|
152
|
+
<span class="url">${esc(req.url)}</span>
|
|
153
|
+
</div>
|
|
154
|
+
|
|
155
|
+
${source ? `
|
|
156
|
+
<div class="section">
|
|
157
|
+
<div class="section-title">Exception Source</div>
|
|
158
|
+
<div class="card code-block">
|
|
159
|
+
${source.map(l => `<div class="code-line${l.isError ? ' error' : ''}"><span class="code-line-num">${l.n}</span><span class="code-line-src">${esc(l.code)}</span></div>`).join('')}
|
|
160
|
+
</div>
|
|
161
|
+
</div>` : ''}
|
|
162
|
+
|
|
163
|
+
<div class="section">
|
|
164
|
+
<div class="section-title">Exception Trace</div>
|
|
165
|
+
<div class="card">
|
|
166
|
+
${appFrames.map(f => frameRow(f, true)).join('')}
|
|
167
|
+
${vendorCount > 0 ? `
|
|
168
|
+
<div class="vendor-toggle" onclick="var el=this.nextElementSibling;el.classList.toggle('open');this.querySelector('span').textContent=el.classList.contains('open')?'Hide ${vendorCount} vendor frames':'${vendorCount} vendor frames'">
|
|
169
|
+
<span>${vendorCount} vendor frames</span><span>↕</span>
|
|
170
|
+
</div>
|
|
171
|
+
<div class="vendor-frames">
|
|
172
|
+
${frames.filter(f => f.isVendor).map(f => frameRow(f, false)).join('')}
|
|
173
|
+
</div>` : ''}
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<div class="section">
|
|
178
|
+
<div class="section-title">Request Headers</div>
|
|
179
|
+
<div class="card">
|
|
180
|
+
<table>
|
|
181
|
+
${Object.entries(req.headers).map(([k, v]) => `<tr><th>${esc(k)}</th><td>${esc(String(v))}</td></tr>`).join('')}
|
|
182
|
+
</table>
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
</body>
|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AC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,iCAAiC,CAAC,CAAC,CAAC,sCAAsC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;;SAE9K,CAAC,CAAC,CAAC,EAAE;;;;;QAKN,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC;oLAC0J,WAAW,oBAAoB,WAAW;kBAC5M,WAAW;;;YAGjB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;eACjE,CAAC,CAAC,CAAC,EAAE;;;;;;;;UAQV,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;;;;;;;QAO/G,CAAA;AACR,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ServerAdapterProvider } from '@rudderjs/contracts';
|
|
2
|
+
export interface HonoConfig {
|
|
3
|
+
/** Port to listen on when using listen() — default 3000 */
|
|
4
|
+
port?: number;
|
|
5
|
+
/** Trust X-Forwarded-* headers from proxies */
|
|
6
|
+
trustProxy?: boolean;
|
|
7
|
+
/** CORS options applied as a global middleware */
|
|
8
|
+
cors?: {
|
|
9
|
+
origin?: string;
|
|
10
|
+
methods?: string;
|
|
11
|
+
headers?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function hono(config?: HonoConfig): ServerAdapterProvider;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAEV,qBAAqB,EAMtB,MAAM,qBAAqB,CAAA;AAK5B,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,+CAA+C;IAC/C,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,kDAAkD;IAClD,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAG,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,CAAA;CACF;AA4PD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,qBAAqB,CA8EnE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { renderErrorPage } from './error-page.js';
|
|
3
|
+
import { serve } from '@hono/node-server';
|
|
4
|
+
import http from 'node:http';
|
|
5
|
+
// ─── WebSocket upgrade handler for production ──────────────
|
|
6
|
+
// Monkey-patch http.createServer at module load time so that any HTTP server
|
|
7
|
+
// created after providers boot gets the WS upgrade handler attached.
|
|
8
|
+
// In dev, the @rudderjs/vite plugin does the same.
|
|
9
|
+
//
|
|
10
|
+
// IMPORTANT: Skip the patch if @rudderjs/vite has already patched http.createServer.
|
|
11
|
+
// Otherwise both patches would attach listeners, causing handleUpgrade() to be
|
|
12
|
+
// called twice for the same socket ("called more than once" error in dev mode).
|
|
13
|
+
const _G = globalThis;
|
|
14
|
+
if (!_G['__rudderjs_http_upgrade_patched__']) {
|
|
15
|
+
_G['__rudderjs_http_upgrade_patched__'] = true;
|
|
16
|
+
const _origCreateServer = http.createServer.bind(http);
|
|
17
|
+
http.createServer = ((...args) => {
|
|
18
|
+
const srv = _origCreateServer(...args);
|
|
19
|
+
srv.on('upgrade', (req, socket, head) => {
|
|
20
|
+
const handler = _G['__rudderjs_ws_upgrade__'];
|
|
21
|
+
handler?.(req, socket, head);
|
|
22
|
+
});
|
|
23
|
+
return srv;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
import { attachInputAccessors } from '@rudderjs/contracts';
|
|
27
|
+
// ─── Request Normalizer ────────────────────────────────────
|
|
28
|
+
function normalizeRequest(c) {
|
|
29
|
+
const url = new URL(c.req.url);
|
|
30
|
+
const req = {
|
|
31
|
+
method: c.req.method,
|
|
32
|
+
url: c.req.url,
|
|
33
|
+
path: url.pathname,
|
|
34
|
+
query: Object.fromEntries(url.searchParams.entries()),
|
|
35
|
+
params: c.req.param() ?? {},
|
|
36
|
+
headers: Object.fromEntries(Object.entries(c.req.header() ?? {}).map(([k, v]) => [k, String(v)])),
|
|
37
|
+
body: null, // populated lazily per route
|
|
38
|
+
raw: c,
|
|
39
|
+
};
|
|
40
|
+
// Forward per-request augmentations stored on c by middleware (e.g. session, user).
|
|
41
|
+
// Both applyMiddleware and registerRoute call normalizeRequest(c) with the same
|
|
42
|
+
// Hono context, so getters ensure the route handler always sees what was set.
|
|
43
|
+
const ctx = c;
|
|
44
|
+
Object.defineProperty(req, 'session', {
|
|
45
|
+
get: () => ctx['__rjs_session'],
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(req, 'user', {
|
|
50
|
+
get: () => ctx['__rjs_user'],
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
});
|
|
54
|
+
attachInputAccessors(req);
|
|
55
|
+
return req;
|
|
56
|
+
}
|
|
57
|
+
// ─── Response Normalizer ───────────────────────────────────
|
|
58
|
+
function normalizeResponse(c) {
|
|
59
|
+
let statusCode = 200;
|
|
60
|
+
const headers = {};
|
|
61
|
+
return {
|
|
62
|
+
raw: c,
|
|
63
|
+
status(code) {
|
|
64
|
+
statusCode = code;
|
|
65
|
+
return this;
|
|
66
|
+
},
|
|
67
|
+
header(key, value) {
|
|
68
|
+
headers[key] = value;
|
|
69
|
+
return this;
|
|
70
|
+
},
|
|
71
|
+
json(data) {
|
|
72
|
+
c.header('Content-Type', 'application/json');
|
|
73
|
+
Object.entries(headers).forEach(([k, v]) => c.header(k, v));
|
|
74
|
+
c.status(statusCode);
|
|
75
|
+
// Hono v4: c.json() returns a Response but does NOT set c.res automatically.
|
|
76
|
+
// We must set c.res explicitly so Hono/srvx always has a valid response to send.
|
|
77
|
+
c.res = c.json(data);
|
|
78
|
+
return c.res;
|
|
79
|
+
},
|
|
80
|
+
send(data) {
|
|
81
|
+
Object.entries(headers).forEach(([k, v]) => c.header(k, v));
|
|
82
|
+
c.status(statusCode);
|
|
83
|
+
// Use c.body() (not c.text()) so a custom Content-Type set via res.header()
|
|
84
|
+
// is preserved. c.text() forces Content-Type: text/plain and overrides headers.
|
|
85
|
+
if (headers['Content-Type'] || headers['content-type']) {
|
|
86
|
+
c.res = c.body(data);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
c.res = c.text(data);
|
|
90
|
+
}
|
|
91
|
+
return c.res;
|
|
92
|
+
},
|
|
93
|
+
redirect(url, code = 302) {
|
|
94
|
+
c.res = c.redirect(url, code);
|
|
95
|
+
return c.res;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// ─── Request logger ────────────────────────────────────────
|
|
100
|
+
const g = globalThis;
|
|
101
|
+
const isTTY = process.stdout.isTTY ?? false;
|
|
102
|
+
function clr(code, s) {
|
|
103
|
+
return isTTY ? `\x1b[${code}m${s}\x1b[0m` : s;
|
|
104
|
+
}
|
|
105
|
+
const dim = (s) => clr('2', s);
|
|
106
|
+
const cyan = (s) => isTTY ? `\x1b[38;2;80;200;220m${s}\x1b[0m` : s;
|
|
107
|
+
function statusColor(status) {
|
|
108
|
+
if (!isTTY)
|
|
109
|
+
return String(status);
|
|
110
|
+
const s = String(status);
|
|
111
|
+
// 24-bit truecolor — exact RGB, not subject to terminal theme remapping
|
|
112
|
+
if (status < 300)
|
|
113
|
+
return `\x1b[38;2;80;210;100m${s}\x1b[0m`; // green
|
|
114
|
+
if (status < 400)
|
|
115
|
+
return `\x1b[38;2;80;200;220m${s}\x1b[0m`; // cyan
|
|
116
|
+
if (status < 500)
|
|
117
|
+
return `\x1b[38;2;250;190;50m${s}\x1b[0m`; // yellow
|
|
118
|
+
return `\x1b[38;2;255;85;85m${s}\x1b[0m`; // red
|
|
119
|
+
}
|
|
120
|
+
function nextReqId() {
|
|
121
|
+
g['__rudderjs_req_n__'] = (g['__rudderjs_req_n__'] ?? 0) + 1;
|
|
122
|
+
return g['__rudderjs_req_n__'];
|
|
123
|
+
}
|
|
124
|
+
function ts() {
|
|
125
|
+
const d = new Date();
|
|
126
|
+
const hh = String(d.getHours()).padStart(2, '0');
|
|
127
|
+
const mm = String(d.getMinutes()).padStart(2, '0');
|
|
128
|
+
const ss = String(d.getSeconds()).padStart(2, '0');
|
|
129
|
+
return `${hh}:${mm}:${ss}`;
|
|
130
|
+
}
|
|
131
|
+
function duration(ms) {
|
|
132
|
+
if (ms >= 1000)
|
|
133
|
+
return `~${(ms / 1000).toFixed(2)}s`;
|
|
134
|
+
if (ms < 1)
|
|
135
|
+
return `<1ms`;
|
|
136
|
+
if (ms < 10)
|
|
137
|
+
return `~${ms.toFixed(1)}ms`;
|
|
138
|
+
return `~${Math.round(ms)}ms`;
|
|
139
|
+
}
|
|
140
|
+
// Fixed column widths (pad raw strings BEFORE coloring — ANSI codes must not affect padding)
|
|
141
|
+
const COUNTER_WIDTH = 3; // " #1" "#10" "#100"
|
|
142
|
+
const LOG_WIDTH = 50; // path + dots + duration combined
|
|
143
|
+
function formatRequestLog(n, path, status, ms) {
|
|
144
|
+
const counterStr = `#${n}`.padStart(COUNTER_WIDTH);
|
|
145
|
+
const durStr = duration(ms);
|
|
146
|
+
const dots = dim('.'.repeat(Math.max(4, LOG_WIDTH - path.length - durStr.length)));
|
|
147
|
+
return `${dim(ts())} ${cyan(counterStr)} ${path} ${dots} ${durStr} ${statusColor(status)}`;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns the display path to log, or null to skip the request entirely.
|
|
151
|
+
*
|
|
152
|
+
* - Vite internals / node_modules → null (skip)
|
|
153
|
+
* - Vike client-side nav (pageContext.json) → clean page path + " ↩ nav"
|
|
154
|
+
* - Static assets (.js, .css, .ico, …) → null (skip)
|
|
155
|
+
* - Everything else → path as-is
|
|
156
|
+
*/
|
|
157
|
+
function logPath(path) {
|
|
158
|
+
if (path.startsWith('/@') || path.startsWith('/node_modules'))
|
|
159
|
+
return null;
|
|
160
|
+
// Vike client-side navigation: /todos/index.pageContext.json → /todos ↩ nav
|
|
161
|
+
if (path.endsWith('.pageContext.json')) {
|
|
162
|
+
const page = path
|
|
163
|
+
.replace(/\/index\.pageContext\.json$/, '')
|
|
164
|
+
.replace(/\.pageContext\.json$/, '');
|
|
165
|
+
return `${page || '/'} ↩ nav`;
|
|
166
|
+
}
|
|
167
|
+
// Skip static assets — anything whose last segment has a file extension
|
|
168
|
+
const last = path.split('/').pop() ?? '';
|
|
169
|
+
if (last.includes('.'))
|
|
170
|
+
return null;
|
|
171
|
+
return path;
|
|
172
|
+
}
|
|
173
|
+
// ─── Hono Adapter ─────────────────────────────────────────
|
|
174
|
+
class HonoAdapter {
|
|
175
|
+
app;
|
|
176
|
+
_errorHandler;
|
|
177
|
+
constructor(app) {
|
|
178
|
+
this.app = app ?? new Hono();
|
|
179
|
+
}
|
|
180
|
+
setErrorHandler(fn) {
|
|
181
|
+
this._errorHandler = fn;
|
|
182
|
+
}
|
|
183
|
+
/** @internal — used by createFetchHandler after setup() runs */
|
|
184
|
+
getErrorHandler() { return this._errorHandler; }
|
|
185
|
+
registerRoute(route) {
|
|
186
|
+
const method = (route.method === 'ALL' ? 'all' : route.method.toLowerCase());
|
|
187
|
+
this.app[method](route.path, async (c) => {
|
|
188
|
+
const req = normalizeRequest(c);
|
|
189
|
+
const res = normalizeResponse(c);
|
|
190
|
+
// Parse body for mutating methods — JSON only; leave multipart/form-data untouched
|
|
191
|
+
if (['POST', 'PUT', 'PATCH'].includes(route.method)) {
|
|
192
|
+
const ct = c.req.header('content-type') ?? '';
|
|
193
|
+
if (ct.includes('application/json')) {
|
|
194
|
+
try {
|
|
195
|
+
req.body = await c.req.json();
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
req.body = {};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Run middleware chain with the handler as the final step.
|
|
203
|
+
// Middleware and handler share the same `res` so headers set by middleware
|
|
204
|
+
// (e.g. Set-Cookie from SessionMiddleware) are included in the final response.
|
|
205
|
+
// We always return `c.res` at the end — middleware that runs after the handler
|
|
206
|
+
// (like session.save()) can modify `c.res` and their changes will be included.
|
|
207
|
+
const middleware = [...route.middleware];
|
|
208
|
+
let idx = 0;
|
|
209
|
+
const next = async () => {
|
|
210
|
+
const fn = middleware[idx++];
|
|
211
|
+
if (fn) {
|
|
212
|
+
await fn(req, res, next);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// All middleware passed — run the handler with the same res
|
|
216
|
+
const result = await route.handler(req, res);
|
|
217
|
+
if (result instanceof Response) {
|
|
218
|
+
c.res = result;
|
|
219
|
+
}
|
|
220
|
+
else if (result !== undefined && result !== null) {
|
|
221
|
+
c.res = c.json(result);
|
|
222
|
+
}
|
|
223
|
+
// else: handler called res.json()/res.send() which already set c.res
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
await next();
|
|
227
|
+
return c.res;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
applyMiddleware(middleware) {
|
|
231
|
+
this.app.use('*', async (c, honoNext) => {
|
|
232
|
+
const req = normalizeRequest(c);
|
|
233
|
+
const res = normalizeResponse(c);
|
|
234
|
+
await middleware(req, res, honoNext);
|
|
235
|
+
// Hono v4 requires the handler to finalize the context.
|
|
236
|
+
// c.res is always a valid Response (downstream response, or Hono's 404 default).
|
|
237
|
+
// Returning it here covers both cases: pass-through (next was called) and
|
|
238
|
+
// short-circuit (middleware set c.res via normalizeResponse.json/send).
|
|
239
|
+
return c.res;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
listen(port, callback) {
|
|
243
|
+
serve({ fetch: this.app.fetch, port: port }, () => {
|
|
244
|
+
callback?.();
|
|
245
|
+
console.log(`[RudderJS] Server running on http://localhost:${port}`);
|
|
246
|
+
});
|
|
247
|
+
// The WebSocket upgrade handler is attached automatically via the
|
|
248
|
+
// http.createServer monkey-patch at the top of this file. Attaching it
|
|
249
|
+
// again here would cause "handleUpgrade called more than once" errors
|
|
250
|
+
// because both listeners would fire for the same upgrade event.
|
|
251
|
+
}
|
|
252
|
+
getNativeServer() {
|
|
253
|
+
return this.app;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// ─── Factory ───────────────────────────────────────────────
|
|
257
|
+
export function hono(config = {}) {
|
|
258
|
+
return {
|
|
259
|
+
type: 'hono',
|
|
260
|
+
create() {
|
|
261
|
+
return new HonoAdapter();
|
|
262
|
+
},
|
|
263
|
+
createApp() {
|
|
264
|
+
return new Hono();
|
|
265
|
+
},
|
|
266
|
+
async createFetchHandler(setup) {
|
|
267
|
+
// Dynamic import keeps @vikejs/hono out of the vite.config.ts load path
|
|
268
|
+
const vike = (await import('@vikejs/hono')).default;
|
|
269
|
+
const app = new Hono();
|
|
270
|
+
// CORS — applied before routes if configured
|
|
271
|
+
if (config.cors) {
|
|
272
|
+
const { cors } = config;
|
|
273
|
+
app.use('*', async (c, next) => {
|
|
274
|
+
c.header('Access-Control-Allow-Origin', cors.origin ?? '*');
|
|
275
|
+
c.header('Access-Control-Allow-Methods', cors.methods ?? 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
|
|
276
|
+
c.header('Access-Control-Allow-Headers', cors.headers ?? 'Content-Type,Authorization');
|
|
277
|
+
if (c.req.method === 'OPTIONS')
|
|
278
|
+
return new Response(null, { status: 204 });
|
|
279
|
+
await next();
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const isProd = process.env['APP_ENV'] === 'production' || process.env['NODE_ENV'] === 'production';
|
|
283
|
+
const adapter = new HonoAdapter(app);
|
|
284
|
+
setup?.(adapter);
|
|
285
|
+
// Install error handler — setup() may have registered one via adapter.setErrorHandler().
|
|
286
|
+
// The registered handler auto-handles ValidationError → 422 and re-throws everything
|
|
287
|
+
// else, which falls through to the dev error page (dev) or a JSON 500 (prod).
|
|
288
|
+
const userHandler = adapter.getErrorHandler();
|
|
289
|
+
if (userHandler) {
|
|
290
|
+
app.onError(async (err, c) => {
|
|
291
|
+
try {
|
|
292
|
+
return await userHandler(err, normalizeRequest(c));
|
|
293
|
+
}
|
|
294
|
+
catch (e2) {
|
|
295
|
+
const thrown = e2 instanceof Error ? e2 : new Error(String(e2));
|
|
296
|
+
if (!isProd) {
|
|
297
|
+
const html = renderErrorPage(thrown, { method: c.req.method, url: c.req.url, headers: Object.fromEntries(Object.entries(c.req.header())) });
|
|
298
|
+
return c.html(html, 500);
|
|
299
|
+
}
|
|
300
|
+
return new Response(JSON.stringify({ message: 'Internal Server Error' }), {
|
|
301
|
+
status: 500,
|
|
302
|
+
headers: { 'Content-Type': 'application/json' },
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
else if (!isProd) {
|
|
308
|
+
app.onError((err, c) => {
|
|
309
|
+
const html = renderErrorPage(err instanceof Error ? err : new Error(String(err)), { method: c.req.method, url: c.req.url, headers: Object.fromEntries(Object.entries(c.req.header())) });
|
|
310
|
+
return c.html(html, 500);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
// Attach Vike SSR middleware
|
|
314
|
+
vike(app);
|
|
315
|
+
// Logging at the outermost fetch level catches ALL requests — including Vike's
|
|
316
|
+
// client-side navigation data fetches, which bypass the Hono middleware chain.
|
|
317
|
+
return async (request) => {
|
|
318
|
+
const display = logPath(new URL(request.url).pathname);
|
|
319
|
+
if (display === null)
|
|
320
|
+
return app.fetch(request);
|
|
321
|
+
const n = nextReqId();
|
|
322
|
+
const start = performance.now();
|
|
323
|
+
const res = await app.fetch(request);
|
|
324
|
+
console.log(formatRequestLog(n, display, res.status, performance.now() - start));
|
|
325
|
+
return res;
|
|
326
|
+
};
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAA;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,8DAA8D;AAC9D,6EAA6E;AAC7E,qEAAqE;AACrE,mDAAmD;AACnD,EAAE;AACF,qFAAqF;AACrF,+EAA+E;AAC/E,gFAAgF;AAChF,MAAM,EAAE,GAAG,UAAqC,CAAA;AAChD,IAAI,CAAC,EAAE,CAAC,mCAAmC,CAAC,EAAE,CAAC;IAC7C,EAAE,CAAC,mCAAmC,CAAC,GAAG,IAAI,CAAA;IAC9C,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACtD,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,IAA0C,EAAE,EAAE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": "https://github.com/rudderjs/rudder",
|
|
8
|
+
"directory": "packages/server-hono"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@hono/node-server": "^1.19.9",
|
|
24
|
+
"@vikejs/hono": "^0.2.0",
|
|
25
|
+
"hono": "^4.12.0",
|
|
26
|
+
"@rudderjs/contracts": "0.0.3"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.0.0",
|
|
30
|
+
"typescript": "^5.4.0"
|
|
31
|
+
},
|
|
32
|
+
"author": "Suleiman Shahbari",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.build.json",
|
|
35
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"lint": "eslint src",
|
|
38
|
+
"clean": "rm -rf dist",
|
|
39
|
+
"test": "tsc -p tsconfig.test.json && node --test dist-test/index.test.js; EXIT=$?; rm -rf dist-test; exit $EXIT"
|
|
40
|
+
}
|
|
41
|
+
}
|