@nexus_js/server 0.6.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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/actions.d.ts +158 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +396 -0
- package/dist/actions.js.map +1 -0
- package/dist/context.d.ts +41 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +68 -0
- package/dist/context.js.map +1 -0
- package/dist/csrf.d.ts +56 -0
- package/dist/csrf.d.ts.map +1 -0
- package/dist/csrf.js +153 -0
- package/dist/csrf.js.map +1 -0
- package/dist/dev-assets.d.ts +31 -0
- package/dist/dev-assets.d.ts.map +1 -0
- package/dist/dev-assets.js +198 -0
- package/dist/dev-assets.js.map +1 -0
- package/dist/error-boundary.d.ts +87 -0
- package/dist/error-boundary.d.ts.map +1 -0
- package/dist/error-boundary.js +181 -0
- package/dist/error-boundary.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +277 -0
- package/dist/index.js.map +1 -0
- package/dist/load-module.d.ts +26 -0
- package/dist/load-module.d.ts.map +1 -0
- package/dist/load-module.js +288 -0
- package/dist/load-module.js.map +1 -0
- package/dist/logger.d.ts +63 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +158 -0
- package/dist/logger.js.map +1 -0
- package/dist/navigate.d.ts +21 -0
- package/dist/navigate.d.ts.map +1 -0
- package/dist/navigate.js +45 -0
- package/dist/navigate.js.map +1 -0
- package/dist/rate-limit.d.ts +71 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +136 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/renderer.d.ts +92 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +386 -0
- package/dist/renderer.js.map +1 -0
- package/dist/streaming.d.ts +98 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +216 -0
- package/dist/streaming.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nexus Error Boundaries — file-based resilience system.
|
|
3
|
+
*
|
|
4
|
+
* Convention (mirrors Next.js App Router):
|
|
5
|
+
*
|
|
6
|
+
* routes/
|
|
7
|
+
* ├── error.nx ← catches errors in the root layout
|
|
8
|
+
* ├── dashboard/
|
|
9
|
+
* │ ├── error.nx ← catches errors in /dashboard/**
|
|
10
|
+
* │ ├── +layout.nx
|
|
11
|
+
* │ └── +page.nx
|
|
12
|
+
* └── blog/
|
|
13
|
+
* ├── [slug]/
|
|
14
|
+
* │ ├── error.nx ← catches errors ONLY in /blog/:slug
|
|
15
|
+
* │ └── +page.nx
|
|
16
|
+
* └── not-found.nx ← custom 404 for /blog/**
|
|
17
|
+
*
|
|
18
|
+
* The error.nx component receives:
|
|
19
|
+
* - error: { message, name, digest? }
|
|
20
|
+
* - reset: () => void (client-side — triggers re-render)
|
|
21
|
+
*
|
|
22
|
+
* Island hydration for error.nx:
|
|
23
|
+
* The "reset" button must be an island (client:load) to be interactive.
|
|
24
|
+
* The error info is server-rendered (no JS needed to display it).
|
|
25
|
+
*
|
|
26
|
+
* Usage in error.nx:
|
|
27
|
+
* ---
|
|
28
|
+
* const { error } = ctx.errorBoundary;
|
|
29
|
+
* ---
|
|
30
|
+
* <script>
|
|
31
|
+
* const { reset } = $props();
|
|
32
|
+
* </script>
|
|
33
|
+
* <div class="error-boundary" client:load>
|
|
34
|
+
* <h2>Something went wrong</h2>
|
|
35
|
+
* <p>{error.message}</p>
|
|
36
|
+
* <button onclick={reset}>Try again</button>
|
|
37
|
+
* </div>
|
|
38
|
+
*/
|
|
39
|
+
import { access } from 'node:fs/promises';
|
|
40
|
+
import { join, dirname } from 'node:path';
|
|
41
|
+
/**
|
|
42
|
+
* Finds the nearest `error.nx` file to a given route filepath.
|
|
43
|
+
* Walks up the directory tree until it finds one or reaches the routes root.
|
|
44
|
+
*/
|
|
45
|
+
export async function findErrorBoundary(routeFilepath, routesRoot) {
|
|
46
|
+
let dir = dirname(routeFilepath);
|
|
47
|
+
while (dir.startsWith(routesRoot)) {
|
|
48
|
+
const candidate = join(dir, 'error.nx');
|
|
49
|
+
try {
|
|
50
|
+
await access(candidate);
|
|
51
|
+
return candidate;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// No error.nx here — go up one level
|
|
55
|
+
const parent = dirname(dir);
|
|
56
|
+
if (parent === dir)
|
|
57
|
+
break; // Reached filesystem root
|
|
58
|
+
dir = parent;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null; // No error boundary found
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Finds the nearest `not-found.nx` for a given route directory.
|
|
65
|
+
*/
|
|
66
|
+
export async function findNotFoundBoundary(routeFilepath, routesRoot) {
|
|
67
|
+
let dir = dirname(routeFilepath);
|
|
68
|
+
while (dir.startsWith(routesRoot)) {
|
|
69
|
+
const candidate = join(dir, 'not-found.nx');
|
|
70
|
+
try {
|
|
71
|
+
await access(candidate);
|
|
72
|
+
return candidate;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
const parent = dirname(dir);
|
|
76
|
+
if (parent === dir)
|
|
77
|
+
break;
|
|
78
|
+
dir = parent;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Renders an error boundary file to HTML.
|
|
85
|
+
* Sanitizes error info for production (hides stack, generates digest).
|
|
86
|
+
*/
|
|
87
|
+
export async function renderErrorBoundary(boundaryFile, originalError, ctx, opts) {
|
|
88
|
+
const error = normalizeError(originalError, opts.dev);
|
|
89
|
+
// Try to import and render the error.nx boundary
|
|
90
|
+
try {
|
|
91
|
+
const mod = await import(/* @vite-ignore */ boundaryFile);
|
|
92
|
+
if (typeof mod.render === 'function') {
|
|
93
|
+
const result = await mod.render({ ...ctx, errorBoundary: { error } });
|
|
94
|
+
return result.html ?? buildDefaultErrorHTML(error, opts.dev);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (renderErr) {
|
|
98
|
+
console.error('[Nexus] Error boundary itself threw:', renderErr);
|
|
99
|
+
}
|
|
100
|
+
return buildDefaultErrorHTML(error, opts.dev);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Default error page when no error.nx is found.
|
|
104
|
+
* Shows full details in dev, sanitized message in production.
|
|
105
|
+
*/
|
|
106
|
+
export function buildDefaultErrorHTML(error, dev) {
|
|
107
|
+
const details = dev
|
|
108
|
+
? `<pre style="overflow:auto;background:#1a1a2e;padding:1rem;border-radius:8px;font-size:0.8rem;color:#ff6b6b">${htmlEscape(error.stack ?? '')}</pre>`
|
|
109
|
+
: error.digest
|
|
110
|
+
? `<p style="font-family:monospace;color:#6b6b80;font-size:0.8rem">Error ID: ${error.digest}</p>`
|
|
111
|
+
: '';
|
|
112
|
+
return `<div data-nx-error-boundary style="
|
|
113
|
+
max-width:640px; margin:4rem auto; padding:2rem;
|
|
114
|
+
font-family:system-ui; background:#0a0a0f; color:#e8e8f0;
|
|
115
|
+
border:1px solid #ff3e00; border-radius:12px;
|
|
116
|
+
">
|
|
117
|
+
<h2 style="color:#ff3e00;font-size:1.5rem;margin-bottom:0.5rem">
|
|
118
|
+
${htmlEscape(error.name)}
|
|
119
|
+
</h2>
|
|
120
|
+
<p style="color:#a0a0b8;margin-bottom:1.5rem">${htmlEscape(error.message)}</p>
|
|
121
|
+
${details}
|
|
122
|
+
<button
|
|
123
|
+
onclick="location.reload()"
|
|
124
|
+
style="background:#00d4aa;color:#000;border:none;padding:0.5rem 1.5rem;
|
|
125
|
+
border-radius:6px;cursor:pointer;font-weight:700"
|
|
126
|
+
>Try again</button>
|
|
127
|
+
</div>`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Wraps a render function with error boundary protection.
|
|
131
|
+
* If the render throws, catches it and renders the nearest error.nx.
|
|
132
|
+
*/
|
|
133
|
+
export async function withErrorBoundary(fn, opts) {
|
|
134
|
+
try {
|
|
135
|
+
return await fn();
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
console.error('[Nexus] Route render error:', err);
|
|
139
|
+
// Find nearest error boundary
|
|
140
|
+
const boundaryFile = await findErrorBoundary(opts.routeFilepath, opts.routesRoot);
|
|
141
|
+
const html = boundaryFile
|
|
142
|
+
? await renderErrorBoundary(boundaryFile, err, opts.ctx, { dev: opts.dev })
|
|
143
|
+
: buildDefaultErrorHTML(normalizeError(err, opts.dev), opts.dev);
|
|
144
|
+
return { html: wrapInPage(html), status: 500 };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
148
|
+
function normalizeError(err, dev) {
|
|
149
|
+
if (err instanceof Error) {
|
|
150
|
+
const normalized = {
|
|
151
|
+
message: err.message,
|
|
152
|
+
name: err.name,
|
|
153
|
+
digest: generateDigest(err.message),
|
|
154
|
+
};
|
|
155
|
+
if (dev && err.stack !== undefined) {
|
|
156
|
+
normalized.stack = err.stack;
|
|
157
|
+
}
|
|
158
|
+
return normalized;
|
|
159
|
+
}
|
|
160
|
+
const msg = String(err);
|
|
161
|
+
return {
|
|
162
|
+
message: msg,
|
|
163
|
+
name: 'Error',
|
|
164
|
+
digest: generateDigest(msg),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function generateDigest(msg) {
|
|
168
|
+
let h = 0x811c9dc5;
|
|
169
|
+
for (let i = 0; i < msg.length; i++) {
|
|
170
|
+
h ^= msg.charCodeAt(i);
|
|
171
|
+
h = Math.imul(h, 0x01000193);
|
|
172
|
+
}
|
|
173
|
+
return (h >>> 0).toString(16).slice(0, 8).toUpperCase();
|
|
174
|
+
}
|
|
175
|
+
function wrapInPage(html) {
|
|
176
|
+
return `<!DOCTYPE html><html><body style="background:#0a0a0f">${html}</body></html>`;
|
|
177
|
+
}
|
|
178
|
+
function htmlEscape(s) {
|
|
179
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=error-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.js","sourceRoot":"","sources":["../src/error-boundary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAY,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiB1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,aAAqB,EACrB,UAAkB;IAElB,IAAI,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAEjC,OAAO,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACxC,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;YACrC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,MAAM,KAAK,GAAG;gBAAE,MAAM,CAAC,0BAA0B;YACrD,GAAG,GAAG,MAAM,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,CAAC,0BAA0B;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,aAAqB,EACrB,UAAkB;IAElB,IAAI,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAEjC,OAAO,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,G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
/**
|
|
2
|
+
* Nexus Server — Node.js HTTP server adapter.
|
|
3
|
+
* Handles SSR, static assets, Server Actions and dev HMR.
|
|
4
|
+
*/
|
|
5
|
+
export { createAction, registerAction, ActionError } from './actions.js';
|
|
6
|
+
export { createContext } from './context.js';
|
|
7
|
+
export type { NexusContext, CookieOptions } from './context.js';
|
|
8
|
+
export type { RenderResult, RenderOptions } from './renderer.js';
|
|
9
|
+
export interface RequestLogInfo {
|
|
10
|
+
method: string;
|
|
11
|
+
path: string;
|
|
12
|
+
status: number;
|
|
13
|
+
/** Request duration in milliseconds */
|
|
14
|
+
duration: number;
|
|
15
|
+
/** Cache strategy used by the renderer (e.g. 'swr', 'static-immutable', 'no-store') */
|
|
16
|
+
cacheStrategy?: string;
|
|
17
|
+
/** True when the route was served from a Server Action */
|
|
18
|
+
isAction?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface NexusServerOptions {
|
|
21
|
+
/** Root directory of the Nexus app */
|
|
22
|
+
root: string;
|
|
23
|
+
/** Port to listen on (default: 3000) */
|
|
24
|
+
port?: number;
|
|
25
|
+
/** Enable dev mode (HMR, verbose errors, detailed logs) */
|
|
26
|
+
dev?: boolean;
|
|
27
|
+
/** Static assets directory */
|
|
28
|
+
publicDir?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Called after each HTTP request completes.
|
|
31
|
+
* Use this to implement a custom request logger in the CLI or integrations.
|
|
32
|
+
* The server itself does NOT print request logs — the host controls formatting.
|
|
33
|
+
*/
|
|
34
|
+
onRequest?: (info: RequestLogInfo) => void;
|
|
35
|
+
}
|
|
36
|
+
export declare function createNexusServer(opts: NexusServerOptions): Promise<{
|
|
37
|
+
/** Starts listening. Resolves when the server is bound to the port. */
|
|
38
|
+
listen(): Promise<void>;
|
|
39
|
+
/** Re-scans src/routes — called on file changes in dev mode. */
|
|
40
|
+
reload(): Promise<void>;
|
|
41
|
+
close(): void;
|
|
42
|
+
readonly port: number;
|
|
43
|
+
}>;
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEjE,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5C;AAmBD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB;IA6J5D,uEAAuE;cAC7D,OAAO,CAAC,IAAI,CAAC;IAavB,gEAAgE;cAChD,OAAO,CAAC,IAAI,CAAC;aAQpB,IAAI;;GAMhB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nexus Server — Node.js HTTP server adapter.
|
|
3
|
+
* Handles SSR, static assets, Server Actions and dev HMR.
|
|
4
|
+
*/
|
|
5
|
+
import { createServer } from 'node:http';
|
|
6
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
7
|
+
import { join, extname } from 'node:path';
|
|
8
|
+
import { buildRouteManifest, matchRoute } from '@nexus_js/router';
|
|
9
|
+
import { handleActionRequest } from './actions.js';
|
|
10
|
+
import { handleSSERequestNode, isConnectRequest, topicFromUrl } from '@nexus_js/connect';
|
|
11
|
+
import { buildAggregatedNxStylesheet, bustAggregatedStylesCache, compileIslandClientBundle, isIslandClientRequest, tryServeRuntimeAsset, } from './dev-assets.js';
|
|
12
|
+
import { renderRoute } from './renderer.js';
|
|
13
|
+
import { preloadRegisteredServerActions } from './load-module.js';
|
|
14
|
+
import { createContext, RedirectSignal, NotFoundSignal } from './context.js';
|
|
15
|
+
export { createAction, registerAction, ActionError } from './actions.js';
|
|
16
|
+
export { createContext } from './context.js';
|
|
17
|
+
const MIME_TYPES = {
|
|
18
|
+
'.html': 'text/html; charset=utf-8',
|
|
19
|
+
'.js': 'application/javascript; charset=utf-8',
|
|
20
|
+
'.mjs': 'application/javascript; charset=utf-8',
|
|
21
|
+
'.css': 'text/css; charset=utf-8',
|
|
22
|
+
'.json': 'application/json',
|
|
23
|
+
'.png': 'image/png',
|
|
24
|
+
'.jpg': 'image/jpeg',
|
|
25
|
+
'.jpeg': 'image/jpeg',
|
|
26
|
+
'.svg': 'image/svg+xml',
|
|
27
|
+
'.ico': 'image/x-icon',
|
|
28
|
+
'.woff2': 'font/woff2',
|
|
29
|
+
'.woff': 'font/woff',
|
|
30
|
+
'.avif': 'image/avif',
|
|
31
|
+
'.webp': 'image/webp',
|
|
32
|
+
};
|
|
33
|
+
export async function createNexusServer(opts) {
|
|
34
|
+
const port = opts.port ?? 3000;
|
|
35
|
+
const dev = opts.dev ?? false;
|
|
36
|
+
const routesDir = join(opts.root, 'src', 'routes');
|
|
37
|
+
const publicDir = join(opts.root, opts.publicDir ?? 'public');
|
|
38
|
+
let manifest = await buildRouteManifest(routesDir);
|
|
39
|
+
const renderOpts = {
|
|
40
|
+
dev,
|
|
41
|
+
appRoot: opts.root,
|
|
42
|
+
assets: {
|
|
43
|
+
/** ESM entry + chunks served from @nexus_js/runtime/dist via /_nexus/rt/* */
|
|
44
|
+
runtime: '/_nexus/rt/index.js',
|
|
45
|
+
styles: ['/_nexus/styles.css'],
|
|
46
|
+
islands: new Map(),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const server = createServer(async (req, res) => {
|
|
50
|
+
const t0 = Date.now();
|
|
51
|
+
const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
|
|
52
|
+
const method = req.method ?? 'GET';
|
|
53
|
+
// Capture cache strategy before headers are flushed, then call onRequest hook
|
|
54
|
+
let _cacheStrategy;
|
|
55
|
+
let _isAction = false;
|
|
56
|
+
if (opts.onRequest) {
|
|
57
|
+
res.on('finish', () => {
|
|
58
|
+
const info = {
|
|
59
|
+
method,
|
|
60
|
+
path: url.pathname,
|
|
61
|
+
status: res.statusCode,
|
|
62
|
+
duration: Date.now() - t0,
|
|
63
|
+
isAction: _isAction,
|
|
64
|
+
};
|
|
65
|
+
if (_cacheStrategy !== undefined)
|
|
66
|
+
info.cacheStrategy = _cacheStrategy;
|
|
67
|
+
opts.onRequest(info);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// ── Server Actions ──────────────────────────────────────────────────────
|
|
71
|
+
if (url.pathname.startsWith('/_nexus/action/')) {
|
|
72
|
+
_isAction = true;
|
|
73
|
+
const request = await incomingMessageToWebRequest(req);
|
|
74
|
+
const response = await handleActionRequest(request);
|
|
75
|
+
await webToNodeResponse(response, res);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// ── Nexus Connect — SSE (/_nexus/connect/:topic) ────────────────────────
|
|
79
|
+
if (method === 'GET' && isConnectRequest(url)) {
|
|
80
|
+
handleSSERequestNode(req, res, topicFromUrl(url));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// ── @nexus_js/runtime ESM (browser import graph: /_nexus/rt/index.js → ./island.js …)
|
|
84
|
+
const rt = await tryServeRuntimeAsset(url.pathname, opts.root);
|
|
85
|
+
if (rt) {
|
|
86
|
+
res.writeHead(200, { 'content-type': rt.contentType });
|
|
87
|
+
res.end(rt.body);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// ── Client island ESM (dynamic import target for <nexus-island>) ───────
|
|
91
|
+
if (isIslandClientRequest(url.pathname) && method === 'GET') {
|
|
92
|
+
const out = await compileIslandClientBundle(opts.root, url);
|
|
93
|
+
res.writeHead(out.status, {
|
|
94
|
+
'content-type': 'application/javascript; charset=utf-8',
|
|
95
|
+
'cache-control': dev ? 'no-store' : 'public, max-age=120',
|
|
96
|
+
});
|
|
97
|
+
res.end(out.body);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// ── Image optimizer (AVIF/WebP/resize) — same contract as Vite dev middleware
|
|
101
|
+
if (url.pathname === '/_nexus/image' && (method === 'GET' || method === 'HEAD')) {
|
|
102
|
+
const request = nodeToWebRequest(req);
|
|
103
|
+
const { handleImageRequest } = await import('@nexus_js/assets');
|
|
104
|
+
const response = await handleImageRequest(request, { publicDir });
|
|
105
|
+
if (method === 'HEAD') {
|
|
106
|
+
const headers = {};
|
|
107
|
+
response.headers.forEach((value, key) => { headers[key] = value; });
|
|
108
|
+
res.writeHead(response.status, headers);
|
|
109
|
+
res.end();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
await webToNodeResponse(response, res);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// ── Aggregated scoped CSS from all .nx files under src/
|
|
116
|
+
if (url.pathname === '/_nexus/styles.css' && method === 'GET') {
|
|
117
|
+
try {
|
|
118
|
+
const css = await buildAggregatedNxStylesheet(opts.root);
|
|
119
|
+
res.writeHead(200, {
|
|
120
|
+
'content-type': 'text/css; charset=utf-8',
|
|
121
|
+
'cache-control': dev ? 'no-store' : 'public, max-age=300',
|
|
122
|
+
});
|
|
123
|
+
res.end(css);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
127
|
+
res.writeHead(500, { 'content-type': 'text/plain; charset=utf-8' });
|
|
128
|
+
res.end(`[Nexus] Failed to build styles: ${msg}`);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// ── Static files ────────────────────────────────────────────────────────
|
|
133
|
+
const staticResult = await serveStatic(url.pathname, publicDir);
|
|
134
|
+
if (staticResult) {
|
|
135
|
+
res.writeHead(200, { 'content-type': staticResult.mime });
|
|
136
|
+
res.end(staticResult.content);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// ── SSR routing ─────────────────────────────────────────────────────────
|
|
140
|
+
const matched = matchRoute(url.pathname, manifest);
|
|
141
|
+
if (!matched) {
|
|
142
|
+
res.writeHead(404, { 'content-type': 'text/html' });
|
|
143
|
+
res.end(notFoundPage(url.pathname, dev));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const request = nodeToWebRequest(req);
|
|
147
|
+
const ctx = createContext(request, matched.params);
|
|
148
|
+
try {
|
|
149
|
+
const result = await renderRoute(matched, ctx, renderOpts);
|
|
150
|
+
_cacheStrategy = result.headers['x-nexus-cache-strategy'];
|
|
151
|
+
res.writeHead(result.status, result.headers);
|
|
152
|
+
res.end(result.html);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (err instanceof RedirectSignal) {
|
|
156
|
+
res.writeHead(err.status, { location: err.location });
|
|
157
|
+
res.end();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (err instanceof NotFoundSignal) {
|
|
161
|
+
res.writeHead(404, { 'content-type': 'text/html' });
|
|
162
|
+
res.end(notFoundPage(url.pathname, dev));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (dev) {
|
|
166
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
167
|
+
const stack = err instanceof Error ? (err.stack ?? '') : '';
|
|
168
|
+
console.error(`\x1b[31m[Nexus Error]\x1b[0m ${method} ${url.pathname}\n ${message}`);
|
|
169
|
+
if (stack)
|
|
170
|
+
stack.split('\n').slice(1, 6).forEach(l => console.error(` \x1b[2m${l.trim()}\x1b[0m`));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
console.error('[Nexus] Unhandled error:', err);
|
|
174
|
+
}
|
|
175
|
+
res.writeHead(500, { 'content-type': 'text/html' });
|
|
176
|
+
res.end(serverErrorPage(err, dev));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return {
|
|
180
|
+
/** Starts listening. Resolves when the server is bound to the port. */
|
|
181
|
+
listen() {
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
void (async () => {
|
|
184
|
+
try {
|
|
185
|
+
await preloadRegisteredServerActions(opts.root, dev);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
console.error('[Nexus] Server action preload failed:', err);
|
|
189
|
+
}
|
|
190
|
+
server.listen(port, () => resolve());
|
|
191
|
+
})().catch(reject);
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
/** Re-scans src/routes — called on file changes in dev mode. */
|
|
195
|
+
async reload() {
|
|
196
|
+
bustAggregatedStylesCache();
|
|
197
|
+
manifest = await buildRouteManifest(routesDir);
|
|
198
|
+
if (dev) {
|
|
199
|
+
await preloadRegisteredServerActions(opts.root, true);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
close() {
|
|
203
|
+
server.close();
|
|
204
|
+
},
|
|
205
|
+
get port() { return port; },
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// ── Adapters ────────────────────────────────────────────────────────────────
|
|
209
|
+
function nodeToWebRequest(req) {
|
|
210
|
+
const url = `http://${req.headers.host ?? 'localhost'}${req.url ?? '/'}`;
|
|
211
|
+
const headers = new Headers();
|
|
212
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
213
|
+
if (value)
|
|
214
|
+
headers.set(key, Array.isArray(value) ? value.join(', ') : value);
|
|
215
|
+
}
|
|
216
|
+
return new Request(url, { method: req.method ?? 'GET', headers });
|
|
217
|
+
}
|
|
218
|
+
/** Full body (for POST server actions — `nodeToWebRequest` omits the stream). */
|
|
219
|
+
async function incomingMessageToWebRequest(req) {
|
|
220
|
+
const url = `http://${req.headers.host ?? 'localhost'}${req.url ?? '/'}`;
|
|
221
|
+
const headers = new Headers();
|
|
222
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
223
|
+
if (value)
|
|
224
|
+
headers.set(key, Array.isArray(value) ? value.join(', ') : value);
|
|
225
|
+
}
|
|
226
|
+
const chunks = [];
|
|
227
|
+
for await (const chunk of req) {
|
|
228
|
+
chunks.push(Buffer.from(chunk));
|
|
229
|
+
}
|
|
230
|
+
const raw = Buffer.concat(chunks);
|
|
231
|
+
const method = req.method ?? 'GET';
|
|
232
|
+
const init = { method, headers };
|
|
233
|
+
if (raw.length > 0 && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
|
|
234
|
+
init.body = new Uint8Array(raw);
|
|
235
|
+
}
|
|
236
|
+
return new Request(url, init);
|
|
237
|
+
}
|
|
238
|
+
async function webToNodeResponse(response, res) {
|
|
239
|
+
const headers = {};
|
|
240
|
+
response.headers.forEach((value, key) => { headers[key] = value; });
|
|
241
|
+
res.writeHead(response.status, headers);
|
|
242
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
243
|
+
res.end(body);
|
|
244
|
+
}
|
|
245
|
+
async function serveStatic(pathname, publicDir) {
|
|
246
|
+
const safePath = join(publicDir, pathname.replace(/^\/+/, ''));
|
|
247
|
+
try {
|
|
248
|
+
const info = await stat(safePath);
|
|
249
|
+
if (!info.isFile())
|
|
250
|
+
return null;
|
|
251
|
+
const content = await readFile(safePath);
|
|
252
|
+
const mime = MIME_TYPES[extname(safePath)] ?? 'application/octet-stream';
|
|
253
|
+
return { content, mime };
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function serverErrorPage(err, dev) {
|
|
260
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
261
|
+
const stack = dev && err instanceof Error ? (err.stack ?? '') : '';
|
|
262
|
+
return `<!DOCTYPE html><html lang="en"><body style="font-family:monospace;padding:2rem;background:#0a0a0f;color:#e8e8f0">
|
|
263
|
+
<h1 style="color:#ff3e00">◆ Nexus — 500 Server Error</h1>
|
|
264
|
+
<pre style="color:#ff6b6b;background:#0d0d1a;padding:1rem;border-radius:6px;overflow:auto">${message}</pre>
|
|
265
|
+
${dev && stack ? `<details open><summary style="cursor:pointer;color:#6b6b80">Stack trace</summary>
|
|
266
|
+
<pre style="font-size:0.75rem;color:#4b5563">${stack.replace(/</g, '<')}</pre>
|
|
267
|
+
</details>` : ''}
|
|
268
|
+
</body></html>`;
|
|
269
|
+
}
|
|
270
|
+
function notFoundPage(pathname, dev) {
|
|
271
|
+
return `<!DOCTYPE html><html><body style="font-family:monospace;padding:2rem;background:#0a0a0f;color:#e8e8f0">
|
|
272
|
+
<h1 style="color:#00d4aa">◆ Nexus — 404</h1>
|
|
273
|
+
<p>No route found for <code style="color:#ff3e00">${pathname}</code></p>
|
|
274
|
+
${dev ? `<p style="color:#6b6b80">Add a file at <code>src/routes${pathname}/+page.nx</code> to create this page.</p>` : ''}
|
|
275
|
+
</body></html>`;
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAmC,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,I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MAC1D,GAAG,CAAC,CAAC,CAAC,0DAA0D,QAAQ,2CAA2C,CAAC,CAAC,CAAC,EAAE;iBAC7G,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load route modules in dev (compile .nx → .mjs) and prod (pre-built .js under .nexus/output).
|
|
3
|
+
*/
|
|
4
|
+
export interface LoadRouteModuleOptions {
|
|
5
|
+
dev: boolean;
|
|
6
|
+
/** App root (where package.json and node_modules live) */
|
|
7
|
+
appRoot: string;
|
|
8
|
+
/** Route pattern from manifest, e.g. `/`, `/editor`, `/blog/:slug` */
|
|
9
|
+
pattern: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Re-import every `*.actions.mjs` under `.nexus/dev-server` so `registerAction` picks up
|
|
13
|
+
* code changes (including edits to files imported from the sidecar, e.g. `$lib/chat-room.js`).
|
|
14
|
+
* Called from `server.reload()` when the CLI file watcher fires.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Loads every route module once so generated `*.actions.*` sidecars run `registerAction`
|
|
18
|
+
* before any HTTP request. Dev: compiles each `.nx` route; prod: imports `*.actions.js` from `.nexus/output`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function preloadRegisteredServerActions(appRoot: string, dev: boolean): Promise<void>;
|
|
21
|
+
export declare function reimportDevActionSidecars(appRoot: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Dynamic import for `.ts`/`.js` routes, compiled `.nx` in dev, or built `.js` in production.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadRouteModule(filepath: string, options: LoadRouteModuleOptions): Promise<Record<string, unknown>>;
|
|
26
|
+
//# sourceMappingURL=load-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-module.d.ts","sourceRoot":"","sources":["../src/load-module.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,OAAO,CAAC;IACb,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;CACjB;AAuID;;;;GAIG;AACH;;;GAGG;AACH,wBAAsB,8BAA8B,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCjG;AAED,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB9E;AAmBD;;GAEG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA0ElC"}
|