@teamvelix/velix 5.0.3 → 5.0.4
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/dist/build/index.js +4 -587
- package/dist/build/index.js.map +1 -1
- package/dist/chunk-7SGDYOVZ.js +136 -0
- package/dist/chunk-7SGDYOVZ.js.map +1 -0
- package/dist/chunk-F24Q2MX3.js +126 -0
- package/dist/chunk-F24Q2MX3.js.map +1 -0
- package/dist/chunk-INOZP2VD.js +165 -0
- package/dist/chunk-INOZP2VD.js.map +1 -0
- package/dist/chunk-NVTZ6HRX.js +2089 -0
- package/dist/chunk-NVTZ6HRX.js.map +1 -0
- package/dist/chunk-OIZNYND3.js +176 -0
- package/dist/chunk-OIZNYND3.js.map +1 -0
- package/dist/chunk-SPIGTNT7.js +406 -0
- package/dist/chunk-SPIGTNT7.js.map +1 -0
- package/dist/client/index.js +2 -147
- package/dist/client/index.js.map +1 -1
- package/dist/config.js +2 -128
- package/dist/config.js.map +1 -1
- package/dist/image-optimizer-I6TWWH6W.js +66 -0
- package/dist/image-optimizer-I6TWWH6W.js.map +1 -0
- package/dist/{index-l0dwPa62.d.ts → index-DYgxL3mE.d.ts} +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +29 -3318
- package/dist/index.js.map +1 -1
- package/dist/islands/index.js +2 -181
- package/dist/islands/index.js.map +1 -1
- package/dist/runtime/start-dev.js +12 -2395
- package/dist/runtime/start-dev.js.map +1 -1
- package/dist/runtime/start-prod.js +5 -2387
- package/dist/runtime/start-prod.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +5 -2491
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,2089 @@
|
|
|
1
|
+
import { logger_default, buildRouteTree, matchRoute } from './chunk-SPIGTNT7.js';
|
|
2
|
+
import { loadConfig, resolvePaths } from './chunk-F24Q2MX3.js';
|
|
3
|
+
import { getRegisteredIslands, generateAdvancedHydrationScript } from './chunk-OIZNYND3.js';
|
|
4
|
+
import http from 'http';
|
|
5
|
+
import fs4 from 'fs';
|
|
6
|
+
import path4 from 'path';
|
|
7
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
8
|
+
import React, { useActionState } from 'react';
|
|
9
|
+
export { useActionState, useOptimistic } from 'react';
|
|
10
|
+
import { renderToString } from 'react-dom/server';
|
|
11
|
+
import { spawnSync, spawn } from 'child_process';
|
|
12
|
+
export { useFormStatus } from 'react-dom';
|
|
13
|
+
import esbuild from 'esbuild';
|
|
14
|
+
|
|
15
|
+
var middlewares = {
|
|
16
|
+
cors(options = {}) {
|
|
17
|
+
const {
|
|
18
|
+
origin = "*",
|
|
19
|
+
methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
20
|
+
headers: allowHeaders = ["Content-Type", "Authorization"],
|
|
21
|
+
credentials = false,
|
|
22
|
+
maxAge = 86400
|
|
23
|
+
} = options;
|
|
24
|
+
return async (req, res, next) => {
|
|
25
|
+
const originHeader = typeof origin === "string" ? origin : origin.includes(req.headers.origin) ? req.headers.origin : "";
|
|
26
|
+
res.header("Access-Control-Allow-Origin", originHeader);
|
|
27
|
+
res.header("Access-Control-Allow-Methods", methods.join(", "));
|
|
28
|
+
res.header("Access-Control-Allow-Headers", allowHeaders.join(", "));
|
|
29
|
+
res.header("Access-Control-Max-Age", String(maxAge));
|
|
30
|
+
if (credentials) {
|
|
31
|
+
res.header("Access-Control-Allow-Credentials", "true");
|
|
32
|
+
}
|
|
33
|
+
if (req.method === "OPTIONS") {
|
|
34
|
+
res.status(204);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
await next();
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
rateLimit(options = {}) {
|
|
41
|
+
const { windowMs = 6e4, max = 100, message = "Too many requests" } = options;
|
|
42
|
+
const store = /* @__PURE__ */ new Map();
|
|
43
|
+
return async (req, res, next) => {
|
|
44
|
+
const ip = req.headers["x-forwarded-for"] || "unknown";
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
const record = store.get(ip);
|
|
47
|
+
if (!record || now > record.resetTime) {
|
|
48
|
+
store.set(ip, { count: 1, resetTime: now + windowMs });
|
|
49
|
+
} else if (record.count >= max) {
|
|
50
|
+
res.status(429).json({ error: message });
|
|
51
|
+
return;
|
|
52
|
+
} else {
|
|
53
|
+
record.count++;
|
|
54
|
+
}
|
|
55
|
+
await next();
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
security() {
|
|
59
|
+
return async (_req, res, next) => {
|
|
60
|
+
res.header("X-Content-Type-Options", "nosniff");
|
|
61
|
+
res.header("X-Frame-Options", "DENY");
|
|
62
|
+
res.header("X-XSS-Protection", "1; mode=block");
|
|
63
|
+
res.header("Referrer-Policy", "strict-origin-when-cross-origin");
|
|
64
|
+
await next();
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
async function loadMiddleware(projectRoot) {
|
|
69
|
+
const middlewareDir = path4.join(projectRoot, "middleware");
|
|
70
|
+
const fns = [];
|
|
71
|
+
if (!fs4.existsSync(middlewareDir)) return fns;
|
|
72
|
+
const files = fs4.readdirSync(middlewareDir).filter((f) => /\.(ts|js)$/.test(f)).sort();
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
try {
|
|
75
|
+
const filePath = path4.join(middlewareDir, file);
|
|
76
|
+
const { pathToFileURL: pathToFileURL3 } = await import('url');
|
|
77
|
+
const url = pathToFileURL3(filePath).href;
|
|
78
|
+
const mod = await import(`${url}?t=${Date.now()}`);
|
|
79
|
+
const fn = mod.default || mod.middleware;
|
|
80
|
+
if (typeof fn === "function") fns.push(fn);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.warn(`\u26A0 Failed to load middleware ${file}: ${err.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return fns;
|
|
86
|
+
}
|
|
87
|
+
async function runMiddleware(req, res, fns) {
|
|
88
|
+
const result = { continue: true, rewritten: false };
|
|
89
|
+
if (fns.length === 0) return result;
|
|
90
|
+
const url = new URL(req.url || "/", `http://${req.headers.host || "localhost"}`);
|
|
91
|
+
const cookies2 = {};
|
|
92
|
+
const cookieHeader = req.headers.cookie;
|
|
93
|
+
if (cookieHeader) {
|
|
94
|
+
cookieHeader.split(";").forEach((c) => {
|
|
95
|
+
const [k, ...v] = c.split("=");
|
|
96
|
+
if (k) cookies2[k.trim()] = v.join("=").trim();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const mReq = {
|
|
100
|
+
url: req.url || "/",
|
|
101
|
+
method: req.method || "GET",
|
|
102
|
+
headers: req.headers,
|
|
103
|
+
cookies: cookies2,
|
|
104
|
+
params: {},
|
|
105
|
+
query: Object.fromEntries(url.searchParams),
|
|
106
|
+
raw: req
|
|
107
|
+
};
|
|
108
|
+
let ended = false;
|
|
109
|
+
const mRes = {
|
|
110
|
+
_statusCode: 200,
|
|
111
|
+
_headers: {},
|
|
112
|
+
_redirectUrl: null,
|
|
113
|
+
_rewriteUrl: null,
|
|
114
|
+
_ended: false,
|
|
115
|
+
status(code) {
|
|
116
|
+
this._statusCode = code;
|
|
117
|
+
return this;
|
|
118
|
+
},
|
|
119
|
+
header(name, value) {
|
|
120
|
+
this._headers[name] = value;
|
|
121
|
+
return this;
|
|
122
|
+
},
|
|
123
|
+
json(data) {
|
|
124
|
+
this._headers["Content-Type"] = "application/json";
|
|
125
|
+
res.writeHead(this._statusCode, this._headers);
|
|
126
|
+
res.end(JSON.stringify(data));
|
|
127
|
+
this._ended = true;
|
|
128
|
+
ended = true;
|
|
129
|
+
},
|
|
130
|
+
redirect(url2, status = 307) {
|
|
131
|
+
this._redirectUrl = url2;
|
|
132
|
+
this._statusCode = status;
|
|
133
|
+
res.writeHead(status, { Location: url2, ...this._headers });
|
|
134
|
+
res.end();
|
|
135
|
+
this._ended = true;
|
|
136
|
+
ended = true;
|
|
137
|
+
},
|
|
138
|
+
rewrite(url2) {
|
|
139
|
+
this._rewriteUrl = url2;
|
|
140
|
+
req.url = url2;
|
|
141
|
+
result.rewritten = true;
|
|
142
|
+
},
|
|
143
|
+
async next() {
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
let index = 0;
|
|
147
|
+
const next = async () => {
|
|
148
|
+
if (ended || index >= fns.length) return;
|
|
149
|
+
const fn = fns[index++];
|
|
150
|
+
await fn(mReq, mRes, next);
|
|
151
|
+
};
|
|
152
|
+
await next();
|
|
153
|
+
if (!ended) {
|
|
154
|
+
for (const [key, value] of Object.entries(mRes._headers)) {
|
|
155
|
+
res.setHeader(key, value);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
result.continue = !ended;
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
function composeMiddleware(...fns) {
|
|
162
|
+
return async (req, res, next) => {
|
|
163
|
+
let index = 0;
|
|
164
|
+
const run = async () => {
|
|
165
|
+
if (index >= fns.length) {
|
|
166
|
+
await next();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const fn = fns[index++];
|
|
170
|
+
await fn(req, res, run);
|
|
171
|
+
};
|
|
172
|
+
await run();
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
var PluginHooks = {
|
|
176
|
+
CONFIG: "config",
|
|
177
|
+
SERVER_START: "server:start",
|
|
178
|
+
REQUEST: "request",
|
|
179
|
+
RESPONSE: "response",
|
|
180
|
+
ROUTES_LOADED: "routes:loaded",
|
|
181
|
+
BEFORE_RENDER: "render:before",
|
|
182
|
+
AFTER_RENDER: "render:after",
|
|
183
|
+
BUILD_START: "build:start",
|
|
184
|
+
BUILD_END: "build:end"
|
|
185
|
+
};
|
|
186
|
+
var PluginManager = class {
|
|
187
|
+
plugins = [];
|
|
188
|
+
hooks = /* @__PURE__ */ new Map();
|
|
189
|
+
/**
|
|
190
|
+
* Register a plugin
|
|
191
|
+
*/
|
|
192
|
+
register(plugin) {
|
|
193
|
+
this.plugins.push(plugin);
|
|
194
|
+
if (plugin.hooks) {
|
|
195
|
+
for (const [hookName, handler] of Object.entries(plugin.hooks)) {
|
|
196
|
+
if (handler) {
|
|
197
|
+
const existing = this.hooks.get(hookName) || [];
|
|
198
|
+
existing.push(handler);
|
|
199
|
+
this.hooks.set(hookName, existing);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Run a hook with arguments
|
|
206
|
+
*/
|
|
207
|
+
async runHook(hookName, ...args) {
|
|
208
|
+
const handlers = this.hooks.get(hookName) || [];
|
|
209
|
+
for (const handler of handlers) {
|
|
210
|
+
await handler(...args);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Run a waterfall hook — each handler transforms the first argument
|
|
215
|
+
*/
|
|
216
|
+
async runWaterfallHook(hookName, value, ...args) {
|
|
217
|
+
const handlers = this.hooks.get(hookName) || [];
|
|
218
|
+
let result = value;
|
|
219
|
+
for (const handler of handlers) {
|
|
220
|
+
const transformed = await handler(result, ...args);
|
|
221
|
+
if (transformed !== void 0) result = transformed;
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get all registered plugins
|
|
227
|
+
*/
|
|
228
|
+
getPlugins() {
|
|
229
|
+
return [...this.plugins];
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Check if a plugin is registered
|
|
233
|
+
*/
|
|
234
|
+
hasPlugin(name) {
|
|
235
|
+
return this.plugins.some((p) => p.name === name);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var pluginManager = new PluginManager();
|
|
239
|
+
async function loadPlugins(projectRoot, config) {
|
|
240
|
+
const pluginEntries = config.plugins || [];
|
|
241
|
+
for (const entry of pluginEntries) {
|
|
242
|
+
try {
|
|
243
|
+
if (typeof entry === "string") {
|
|
244
|
+
const localPath = path4.join(projectRoot, "plugins", entry + ".ts");
|
|
245
|
+
const localPathJs = path4.join(projectRoot, "plugins", entry + ".js");
|
|
246
|
+
const localPathDir = path4.join(projectRoot, "plugins", entry, "index.ts");
|
|
247
|
+
let pluginPath = null;
|
|
248
|
+
if (fs4.existsSync(localPath)) pluginPath = localPath;
|
|
249
|
+
else if (fs4.existsSync(localPathJs)) pluginPath = localPathJs;
|
|
250
|
+
else if (fs4.existsSync(localPathDir)) pluginPath = localPathDir;
|
|
251
|
+
if (pluginPath) {
|
|
252
|
+
const url = pathToFileURL(pluginPath).href;
|
|
253
|
+
const mod = await import(`${url}?t=${Date.now()}`);
|
|
254
|
+
const plugin = mod.default || mod;
|
|
255
|
+
if (plugin.name) {
|
|
256
|
+
pluginManager.register(plugin);
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
try {
|
|
260
|
+
const mod = await import(entry);
|
|
261
|
+
const plugin = mod.default || mod;
|
|
262
|
+
if (plugin.name) pluginManager.register(plugin);
|
|
263
|
+
} catch {
|
|
264
|
+
console.warn(`\u26A0 Plugin not found: ${entry}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} else if (typeof entry === "object" && entry.name) {
|
|
268
|
+
pluginManager.register(entry);
|
|
269
|
+
}
|
|
270
|
+
} catch (err) {
|
|
271
|
+
console.warn(`\u26A0 Failed to load plugin: ${err.message}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function definePlugin(definition) {
|
|
276
|
+
return definition;
|
|
277
|
+
}
|
|
278
|
+
({
|
|
279
|
+
/**
|
|
280
|
+
* Security headers plugin
|
|
281
|
+
*/
|
|
282
|
+
security: definePlugin({
|
|
283
|
+
name: "velix:security",
|
|
284
|
+
hooks: {
|
|
285
|
+
[PluginHooks.RESPONSE]: (_req, res) => {
|
|
286
|
+
if (!res.headersSent) {
|
|
287
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
288
|
+
res.setHeader("X-Frame-Options", "DENY");
|
|
289
|
+
res.setHeader("X-XSS-Protection", "1; mode=block");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}),
|
|
294
|
+
/**
|
|
295
|
+
* Request logging plugin
|
|
296
|
+
*/
|
|
297
|
+
logger: definePlugin({
|
|
298
|
+
name: "velix:logger",
|
|
299
|
+
hooks: {
|
|
300
|
+
[PluginHooks.RESPONSE]: (req, _res, duration) => {
|
|
301
|
+
console.log(` ${req.method} ${req.url} ${duration}ms`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
});
|
|
306
|
+
function detectTailwindCli() {
|
|
307
|
+
const v4 = spawnSync("npx", ["@tailwindcss/cli", "--help"], {
|
|
308
|
+
stdio: "pipe",
|
|
309
|
+
shell: process.platform === "win32",
|
|
310
|
+
timeout: 15e3
|
|
311
|
+
});
|
|
312
|
+
if (v4.status === 0) return "@tailwindcss/cli";
|
|
313
|
+
return "tailwindcss";
|
|
314
|
+
}
|
|
315
|
+
function tailwindPlugin(options = {}) {
|
|
316
|
+
const input = options.input || "./app/globals.css";
|
|
317
|
+
const output = options.output || "./public/tailwind.css";
|
|
318
|
+
options.config || "./tailwind.config.ts";
|
|
319
|
+
let cliCmd = null;
|
|
320
|
+
function getCli() {
|
|
321
|
+
if (!cliCmd) cliCmd = detectTailwindCli();
|
|
322
|
+
return cliCmd;
|
|
323
|
+
}
|
|
324
|
+
return definePlugin({
|
|
325
|
+
name: "velix:tailwind",
|
|
326
|
+
hooks: {
|
|
327
|
+
[PluginHooks.CONFIG]: (config) => {
|
|
328
|
+
const relativeOutput = output.startsWith("./") ? output.substring(1) : output;
|
|
329
|
+
const stylePath = relativeOutput.startsWith("/public") ? relativeOutput.substring(7) : relativeOutput;
|
|
330
|
+
if (!config.styles) config.styles = [];
|
|
331
|
+
if (!config.styles.includes(stylePath)) {
|
|
332
|
+
config.styles.push(stylePath);
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
[PluginHooks.BUILD_START]: async () => {
|
|
336
|
+
logger_default.info("Building Tailwind CSS...");
|
|
337
|
+
try {
|
|
338
|
+
const cli = getCli();
|
|
339
|
+
const args = [cli, "-i", input, "-o", output];
|
|
340
|
+
if (options.minify !== false) args.push("--minify");
|
|
341
|
+
spawnSync("npx", args, {
|
|
342
|
+
stdio: "inherit",
|
|
343
|
+
cwd: process.cwd(),
|
|
344
|
+
shell: process.platform === "win32"
|
|
345
|
+
});
|
|
346
|
+
logger_default.success("Tailwind CSS built successfully");
|
|
347
|
+
} catch (err) {
|
|
348
|
+
logger_default.error("Tailwind build failed", err);
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
[PluginHooks.SERVER_START]: async (server, isDev) => {
|
|
352
|
+
if (!isDev) return;
|
|
353
|
+
if (!fs4.existsSync(input)) {
|
|
354
|
+
logger_default.warn(`Tailwind input file not found: ${input}`);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const outputDir = path4.dirname(output);
|
|
358
|
+
if (!fs4.existsSync(outputDir)) {
|
|
359
|
+
fs4.mkdirSync(outputDir, { recursive: true });
|
|
360
|
+
}
|
|
361
|
+
logger_default.info("Building initial Tailwind CSS...");
|
|
362
|
+
try {
|
|
363
|
+
const cli2 = getCli();
|
|
364
|
+
const buildResult = spawnSync("npx", [cli2, "-i", input, "-o", output], {
|
|
365
|
+
cwd: process.cwd(),
|
|
366
|
+
stdio: "pipe",
|
|
367
|
+
shell: process.platform === "win32"
|
|
368
|
+
});
|
|
369
|
+
if (buildResult.error) {
|
|
370
|
+
logger_default.error("Tailwind CSS not installed. Run: npm install -D tailwindcss @tailwindcss/postcss");
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (buildResult.status !== 0) {
|
|
374
|
+
const errorMsg = buildResult.stderr?.toString() || "Unknown error";
|
|
375
|
+
logger_default.error(`Tailwind build failed: ${errorMsg}`);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
logger_default.success("Tailwind CSS built successfully");
|
|
379
|
+
} catch (err) {
|
|
380
|
+
logger_default.error("Failed to build Tailwind CSS", err);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
logger_default.info("Starting Tailwind CSS watcher...");
|
|
384
|
+
const cli = getCli();
|
|
385
|
+
const watcher = spawn("npx", [cli, "-i", input, "-o", output, "--watch"], {
|
|
386
|
+
stdio: "pipe",
|
|
387
|
+
cwd: process.cwd(),
|
|
388
|
+
shell: process.platform === "win32"
|
|
389
|
+
});
|
|
390
|
+
watcher.stdout.on("data", (data) => {
|
|
391
|
+
const msg = data.toString().trim();
|
|
392
|
+
if (msg && !msg.includes("Rebuilding...") && !msg.includes("Done in")) {
|
|
393
|
+
logger_default.info(`Tailwind: ${msg}`);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
watcher.stderr.on("data", (data) => {
|
|
397
|
+
const msg = data.toString().trim();
|
|
398
|
+
if (msg && !msg.includes("warn")) {
|
|
399
|
+
logger_default.warn(`Tailwind: ${msg}`);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
watcher.on("error", (err) => {
|
|
403
|
+
logger_default.error("Tailwind watcher error", err);
|
|
404
|
+
});
|
|
405
|
+
watcher.on("exit", (code) => {
|
|
406
|
+
if (code !== 0 && code !== null) {
|
|
407
|
+
logger_default.error(`Tailwind watcher exited with code ${code}`);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const cleanup = () => {
|
|
411
|
+
if (watcher && !watcher.killed) {
|
|
412
|
+
watcher.kill();
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
process.on("exit", cleanup);
|
|
416
|
+
process.on("SIGINT", cleanup);
|
|
417
|
+
process.on("SIGTERM", cleanup);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// metadata/index.ts
|
|
424
|
+
function generateMetadataTags(metadata, baseUrl) {
|
|
425
|
+
const tags = [];
|
|
426
|
+
const base = baseUrl || metadata.metadataBase?.toString() || "";
|
|
427
|
+
if (metadata.title) {
|
|
428
|
+
const title = typeof metadata.title === "string" ? metadata.title : metadata.title.absolute || (metadata.title.template ? metadata.title.template.replace("%s", metadata.title.default) : metadata.title.default);
|
|
429
|
+
tags.push(`<title>${escapeHtml(title)}</title>`);
|
|
430
|
+
}
|
|
431
|
+
if (metadata.description) tags.push(`<meta name="description" content="${escapeHtml(metadata.description)}">`);
|
|
432
|
+
if (metadata.keywords) {
|
|
433
|
+
const kw = Array.isArray(metadata.keywords) ? metadata.keywords.join(", ") : metadata.keywords;
|
|
434
|
+
tags.push(`<meta name="keywords" content="${escapeHtml(kw)}">`);
|
|
435
|
+
}
|
|
436
|
+
if (metadata.authors) {
|
|
437
|
+
const authors = Array.isArray(metadata.authors) ? metadata.authors : [metadata.authors];
|
|
438
|
+
authors.forEach((a) => {
|
|
439
|
+
if (a.name) tags.push(`<meta name="author" content="${escapeHtml(a.name)}">`);
|
|
440
|
+
if (a.url) tags.push(`<link rel="author" href="${a.url}">`);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
if (metadata.generator) tags.push(`<meta name="generator" content="${escapeHtml(metadata.generator)}">`);
|
|
444
|
+
if (metadata.applicationName) tags.push(`<meta name="application-name" content="${escapeHtml(metadata.applicationName)}">`);
|
|
445
|
+
if (metadata.referrer) tags.push(`<meta name="referrer" content="${metadata.referrer}">`);
|
|
446
|
+
if (metadata.robots) {
|
|
447
|
+
if (typeof metadata.robots === "string") {
|
|
448
|
+
tags.push(`<meta name="robots" content="${metadata.robots}">`);
|
|
449
|
+
} else {
|
|
450
|
+
tags.push(`<meta name="robots" content="${generateRobotsContent(metadata.robots)}">`);
|
|
451
|
+
if (metadata.robots.googleBot) {
|
|
452
|
+
const gbc = typeof metadata.robots.googleBot === "string" ? metadata.robots.googleBot : generateRobotsContent(metadata.robots.googleBot);
|
|
453
|
+
tags.push(`<meta name="googlebot" content="${gbc}">`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (metadata.viewport) {
|
|
458
|
+
const vc = typeof metadata.viewport === "string" ? metadata.viewport : generateViewportContent(metadata.viewport);
|
|
459
|
+
tags.push(`<meta name="viewport" content="${vc}">`);
|
|
460
|
+
}
|
|
461
|
+
if (metadata.themeColor) {
|
|
462
|
+
const tcs = Array.isArray(metadata.themeColor) ? metadata.themeColor : [metadata.themeColor];
|
|
463
|
+
tcs.forEach((tc) => {
|
|
464
|
+
const media = typeof tc !== "string" && tc.media ? ` media="${tc.media}"` : "";
|
|
465
|
+
const color = typeof tc === "string" ? tc : tc.color;
|
|
466
|
+
tags.push(`<meta name="theme-color" content="${color}"${media}>`);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
if (metadata.colorScheme) tags.push(`<meta name="color-scheme" content="${metadata.colorScheme}">`);
|
|
470
|
+
if (metadata.icons) {
|
|
471
|
+
const addIcon = (icon, defaultRel) => {
|
|
472
|
+
const rel = icon.rel || defaultRel;
|
|
473
|
+
const attrs = [
|
|
474
|
+
icon.type ? ` type="${icon.type}"` : "",
|
|
475
|
+
icon.sizes ? ` sizes="${icon.sizes}"` : "",
|
|
476
|
+
icon.color ? ` color="${icon.color}"` : ""
|
|
477
|
+
].join("");
|
|
478
|
+
tags.push(`<link rel="${rel}" href="${resolveUrl(icon.url, base)}"${attrs}>`);
|
|
479
|
+
};
|
|
480
|
+
if (metadata.icons.icon) {
|
|
481
|
+
(Array.isArray(metadata.icons.icon) ? metadata.icons.icon : [metadata.icons.icon]).forEach((i) => addIcon(i, "icon"));
|
|
482
|
+
}
|
|
483
|
+
if (metadata.icons.apple) {
|
|
484
|
+
(Array.isArray(metadata.icons.apple) ? metadata.icons.apple : [metadata.icons.apple]).forEach((i) => addIcon(i, "apple-touch-icon"));
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (metadata.manifest) tags.push(`<link rel="manifest" href="${resolveUrl(metadata.manifest, base)}">`);
|
|
488
|
+
if (metadata.openGraph) {
|
|
489
|
+
const og = metadata.openGraph;
|
|
490
|
+
if (og.type) tags.push(`<meta property="og:type" content="${og.type}">`);
|
|
491
|
+
if (og.title) tags.push(`<meta property="og:title" content="${escapeHtml(og.title)}">`);
|
|
492
|
+
if (og.description) tags.push(`<meta property="og:description" content="${escapeHtml(og.description)}">`);
|
|
493
|
+
if (og.url) tags.push(`<meta property="og:url" content="${resolveUrl(og.url, base)}">`);
|
|
494
|
+
if (og.siteName) tags.push(`<meta property="og:site_name" content="${escapeHtml(og.siteName)}">`);
|
|
495
|
+
if (og.locale) tags.push(`<meta property="og:locale" content="${og.locale}">`);
|
|
496
|
+
if (og.images) {
|
|
497
|
+
(Array.isArray(og.images) ? og.images : [og.images]).forEach((img) => {
|
|
498
|
+
tags.push(`<meta property="og:image" content="${resolveUrl(img.url, base)}">`);
|
|
499
|
+
if (img.width) tags.push(`<meta property="og:image:width" content="${img.width}">`);
|
|
500
|
+
if (img.height) tags.push(`<meta property="og:image:height" content="${img.height}">`);
|
|
501
|
+
if (img.alt) tags.push(`<meta property="og:image:alt" content="${escapeHtml(img.alt)}">`);
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
if (og.type === "article") {
|
|
505
|
+
if (og.publishedTime) tags.push(`<meta property="article:published_time" content="${og.publishedTime}">`);
|
|
506
|
+
if (og.modifiedTime) tags.push(`<meta property="article:modified_time" content="${og.modifiedTime}">`);
|
|
507
|
+
if (og.tags) og.tags.forEach((t) => tags.push(`<meta property="article:tag" content="${escapeHtml(t)}">`));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (metadata.twitter) {
|
|
511
|
+
const tw = metadata.twitter;
|
|
512
|
+
if (tw.card) tags.push(`<meta name="twitter:card" content="${tw.card}">`);
|
|
513
|
+
if (tw.site) tags.push(`<meta name="twitter:site" content="${tw.site}">`);
|
|
514
|
+
if (tw.creator) tags.push(`<meta name="twitter:creator" content="${tw.creator}">`);
|
|
515
|
+
if (tw.title) tags.push(`<meta name="twitter:title" content="${escapeHtml(tw.title)}">`);
|
|
516
|
+
if (tw.description) tags.push(`<meta name="twitter:description" content="${escapeHtml(tw.description)}">`);
|
|
517
|
+
if (tw.images) {
|
|
518
|
+
(Array.isArray(tw.images) ? tw.images : [tw.images]).forEach((img) => {
|
|
519
|
+
const url = typeof img === "string" ? img : img.url;
|
|
520
|
+
tags.push(`<meta name="twitter:image" content="${resolveUrl(url, base)}">`);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (metadata.verification) {
|
|
525
|
+
if (metadata.verification.google) {
|
|
526
|
+
(Array.isArray(metadata.verification.google) ? metadata.verification.google : [metadata.verification.google]).forEach((v) => tags.push(`<meta name="google-site-verification" content="${v}">`));
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (metadata.alternates) {
|
|
530
|
+
if (metadata.alternates.canonical) tags.push(`<link rel="canonical" href="${resolveUrl(metadata.alternates.canonical, base)}">`);
|
|
531
|
+
if (metadata.alternates.languages) {
|
|
532
|
+
Object.entries(metadata.alternates.languages).forEach(([lang, url]) => {
|
|
533
|
+
tags.push(`<link rel="alternate" hreflang="${lang}" href="${resolveUrl(url, base)}">`);
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return tags.join("\n ");
|
|
538
|
+
}
|
|
539
|
+
function mergeMetadata(parent, child) {
|
|
540
|
+
return {
|
|
541
|
+
...parent,
|
|
542
|
+
...child,
|
|
543
|
+
openGraph: child.openGraph ? { ...parent.openGraph, ...child.openGraph } : parent.openGraph,
|
|
544
|
+
twitter: child.twitter ? { ...parent.twitter, ...child.twitter } : parent.twitter,
|
|
545
|
+
icons: child.icons ? { ...parent.icons, ...child.icons } : parent.icons,
|
|
546
|
+
alternates: child.alternates ? { ...parent.alternates, ...child.alternates } : parent.alternates
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function generateJsonLd(data) {
|
|
550
|
+
return `<script type="application/ld+json">${JSON.stringify(data)}</script>`;
|
|
551
|
+
}
|
|
552
|
+
var jsonLd = {
|
|
553
|
+
website: (c) => ({
|
|
554
|
+
"@context": "https://schema.org",
|
|
555
|
+
"@type": "WebSite",
|
|
556
|
+
name: c.name,
|
|
557
|
+
url: c.url,
|
|
558
|
+
description: c.description
|
|
559
|
+
}),
|
|
560
|
+
article: (c) => ({
|
|
561
|
+
"@context": "https://schema.org",
|
|
562
|
+
"@type": "Article",
|
|
563
|
+
headline: c.headline,
|
|
564
|
+
description: c.description,
|
|
565
|
+
image: c.image,
|
|
566
|
+
datePublished: c.datePublished,
|
|
567
|
+
dateModified: c.dateModified || c.datePublished,
|
|
568
|
+
author: Array.isArray(c.author) ? c.author.map((a) => ({ "@type": "Person", ...a })) : { "@type": "Person", ...c.author }
|
|
569
|
+
}),
|
|
570
|
+
organization: (c) => ({
|
|
571
|
+
"@context": "https://schema.org",
|
|
572
|
+
"@type": "Organization",
|
|
573
|
+
name: c.name,
|
|
574
|
+
url: c.url,
|
|
575
|
+
logo: c.logo,
|
|
576
|
+
sameAs: c.sameAs
|
|
577
|
+
}),
|
|
578
|
+
breadcrumb: (items) => ({
|
|
579
|
+
"@context": "https://schema.org",
|
|
580
|
+
"@type": "BreadcrumbList",
|
|
581
|
+
itemListElement: items.map((item, i) => ({ "@type": "ListItem", position: i + 1, name: item.name, item: item.url }))
|
|
582
|
+
})
|
|
583
|
+
};
|
|
584
|
+
function generateSitemap(routes, baseUrl) {
|
|
585
|
+
const urls = routes.filter((r) => r.type === "page" && !r.path.includes(":") && !r.path.includes("*")).map((r) => {
|
|
586
|
+
const loc = `${baseUrl.replace(/\/$/, "")}${r.path}`;
|
|
587
|
+
return ` <url>
|
|
588
|
+
<loc>${loc}</loc>
|
|
589
|
+
<lastmod>${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}</lastmod>
|
|
590
|
+
<changefreq>weekly</changefreq>
|
|
591
|
+
<priority>${r.path === "/" ? "1.0" : "0.8"}</priority>
|
|
592
|
+
</url>`;
|
|
593
|
+
});
|
|
594
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
595
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
596
|
+
${urls.join("\n")}
|
|
597
|
+
</urlset>`;
|
|
598
|
+
}
|
|
599
|
+
function generateRobotsTxt(baseUrl, options = {}) {
|
|
600
|
+
const lines = ["User-agent: *"];
|
|
601
|
+
if (options.allow) options.allow.forEach((p) => lines.push(`Allow: ${p}`));
|
|
602
|
+
if (options.disallow) options.disallow.forEach((p) => lines.push(`Disallow: ${p}`));
|
|
603
|
+
else lines.push("Allow: /");
|
|
604
|
+
lines.push("", `Sitemap: ${baseUrl.replace(/\/$/, "")}/sitemap.xml`);
|
|
605
|
+
return lines.join("\n");
|
|
606
|
+
}
|
|
607
|
+
function escapeHtml(str) {
|
|
608
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
609
|
+
}
|
|
610
|
+
function resolveUrl(url, base) {
|
|
611
|
+
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) return url;
|
|
612
|
+
return base ? `${base.replace(/\/$/, "")}${url.startsWith("/") ? "" : "/"}${url}` : url;
|
|
613
|
+
}
|
|
614
|
+
function generateRobotsContent(robots) {
|
|
615
|
+
const parts = [];
|
|
616
|
+
if (robots.index !== void 0) parts.push(robots.index ? "index" : "noindex");
|
|
617
|
+
if (robots.follow !== void 0) parts.push(robots.follow ? "follow" : "nofollow");
|
|
618
|
+
if (robots.noarchive) parts.push("noarchive");
|
|
619
|
+
if (robots.nosnippet) parts.push("nosnippet");
|
|
620
|
+
if (robots.noimageindex) parts.push("noimageindex");
|
|
621
|
+
return parts.join(", ") || "index, follow";
|
|
622
|
+
}
|
|
623
|
+
function generateViewportContent(viewport) {
|
|
624
|
+
const parts = [];
|
|
625
|
+
if (viewport.width) parts.push(`width=${viewport.width}`);
|
|
626
|
+
if (viewport.height) parts.push(`height=${viewport.height}`);
|
|
627
|
+
if (viewport.initialScale !== void 0) parts.push(`initial-scale=${viewport.initialScale}`);
|
|
628
|
+
if (viewport.maximumScale !== void 0) parts.push(`maximum-scale=${viewport.maximumScale}`);
|
|
629
|
+
if (viewport.userScalable !== void 0) parts.push(`user-scalable=${viewport.userScalable ? "yes" : "no"}`);
|
|
630
|
+
return parts.join(", ") || "width=device-width, initial-scale=1";
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// helpers.ts
|
|
634
|
+
var RedirectError = class extends Error {
|
|
635
|
+
url;
|
|
636
|
+
statusCode;
|
|
637
|
+
type = "redirect";
|
|
638
|
+
constructor(url, statusCode = 307) {
|
|
639
|
+
super(`Redirect to ${url}`);
|
|
640
|
+
this.name = "RedirectError";
|
|
641
|
+
this.url = url;
|
|
642
|
+
this.statusCode = statusCode;
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
var NotFoundError = class extends Error {
|
|
646
|
+
type = "notFound";
|
|
647
|
+
constructor(message = "Page not found") {
|
|
648
|
+
super(message);
|
|
649
|
+
this.name = "NotFoundError";
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
function redirect(url, type = "replace") {
|
|
653
|
+
const statusCode = type === "permanent" ? 308 : 307;
|
|
654
|
+
throw new RedirectError(url, statusCode);
|
|
655
|
+
}
|
|
656
|
+
function notFound(message) {
|
|
657
|
+
throw new NotFoundError(message);
|
|
658
|
+
}
|
|
659
|
+
function json(data, options = {}) {
|
|
660
|
+
const { status = 200, headers: headers2 = {} } = options;
|
|
661
|
+
return new Response(JSON.stringify(data), {
|
|
662
|
+
status,
|
|
663
|
+
headers: { "Content-Type": "application/json", ...headers2 }
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
function html(content, options = {}) {
|
|
667
|
+
const { status = 200, headers: headers2 = {} } = options;
|
|
668
|
+
return new Response(content, {
|
|
669
|
+
status,
|
|
670
|
+
headers: { "Content-Type": "text/html; charset=utf-8", ...headers2 }
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
function text(content, options = {}) {
|
|
674
|
+
const { status = 200, headers: headers2 = {} } = options;
|
|
675
|
+
return new Response(content, {
|
|
676
|
+
status,
|
|
677
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", ...headers2 }
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
var cookies = {
|
|
681
|
+
parse(cookieHeader) {
|
|
682
|
+
const cookies2 = {};
|
|
683
|
+
if (!cookieHeader) return cookies2;
|
|
684
|
+
cookieHeader.split(";").forEach((cookie) => {
|
|
685
|
+
const [name, ...rest] = cookie.split("=");
|
|
686
|
+
if (name) {
|
|
687
|
+
cookies2[name.trim()] = decodeURIComponent(rest.join("=").trim());
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
return cookies2;
|
|
691
|
+
},
|
|
692
|
+
get(request, name) {
|
|
693
|
+
const cookieHeader = request.headers.get("cookie") || "";
|
|
694
|
+
return this.parse(cookieHeader)[name];
|
|
695
|
+
},
|
|
696
|
+
getAll(request) {
|
|
697
|
+
const cookieHeader = request.headers.get("cookie") || "";
|
|
698
|
+
return this.parse(cookieHeader);
|
|
699
|
+
},
|
|
700
|
+
serialize(name, value, options = {}) {
|
|
701
|
+
let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
702
|
+
if (options.maxAge !== void 0) cookie += `; Max-Age=${options.maxAge}`;
|
|
703
|
+
if (options.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
|
|
704
|
+
if (options.path) cookie += `; Path=${options.path}`;
|
|
705
|
+
if (options.domain) cookie += `; Domain=${options.domain}`;
|
|
706
|
+
if (options.secure) cookie += "; Secure";
|
|
707
|
+
if (options.httpOnly) cookie += "; HttpOnly";
|
|
708
|
+
if (options.sameSite) {
|
|
709
|
+
cookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase() + options.sameSite.slice(1)}`;
|
|
710
|
+
}
|
|
711
|
+
return cookie;
|
|
712
|
+
},
|
|
713
|
+
set(name, value, options = {}) {
|
|
714
|
+
return this.serialize(name, value, {
|
|
715
|
+
path: "/",
|
|
716
|
+
httpOnly: true,
|
|
717
|
+
secure: process.env.NODE_ENV === "production",
|
|
718
|
+
sameSite: "lax",
|
|
719
|
+
...options
|
|
720
|
+
});
|
|
721
|
+
},
|
|
722
|
+
delete(name, options = {}) {
|
|
723
|
+
return this.serialize(name, "", { ...options, path: "/", maxAge: 0 });
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
var headers = {
|
|
727
|
+
create(init) {
|
|
728
|
+
return new Headers(init);
|
|
729
|
+
},
|
|
730
|
+
get(request, name) {
|
|
731
|
+
return request.headers.get(name);
|
|
732
|
+
},
|
|
733
|
+
getAll(request) {
|
|
734
|
+
const result = {};
|
|
735
|
+
request.headers.forEach((value, key) => {
|
|
736
|
+
result[key] = value;
|
|
737
|
+
});
|
|
738
|
+
return result;
|
|
739
|
+
},
|
|
740
|
+
has(request, name) {
|
|
741
|
+
return request.headers.has(name);
|
|
742
|
+
},
|
|
743
|
+
contentType(request) {
|
|
744
|
+
return request.headers.get("content-type");
|
|
745
|
+
},
|
|
746
|
+
acceptsJson(request) {
|
|
747
|
+
const accept = request.headers.get("accept") || "";
|
|
748
|
+
return accept.includes("application/json") || accept.includes("*/*");
|
|
749
|
+
},
|
|
750
|
+
isAjax(request) {
|
|
751
|
+
return request.headers.get("x-requested-with") === "XMLHttpRequest" || this.acceptsJson(request);
|
|
752
|
+
},
|
|
753
|
+
authorization(request) {
|
|
754
|
+
const auth = request.headers.get("authorization");
|
|
755
|
+
if (!auth) return null;
|
|
756
|
+
const [type, ...rest] = auth.split(" ");
|
|
757
|
+
return { type: type.toLowerCase(), credentials: rest.join(" ") };
|
|
758
|
+
},
|
|
759
|
+
bearerToken(request) {
|
|
760
|
+
const auth = this.authorization(request);
|
|
761
|
+
return auth?.type === "bearer" ? auth.credentials : null;
|
|
762
|
+
},
|
|
763
|
+
security() {
|
|
764
|
+
return {
|
|
765
|
+
"X-Content-Type-Options": "nosniff",
|
|
766
|
+
"X-Frame-Options": "DENY",
|
|
767
|
+
"X-XSS-Protection": "1; mode=block",
|
|
768
|
+
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
769
|
+
"Permissions-Policy": "camera=(), microphone=(), geolocation=()"
|
|
770
|
+
};
|
|
771
|
+
},
|
|
772
|
+
cors(options = {}) {
|
|
773
|
+
const {
|
|
774
|
+
origin = "*",
|
|
775
|
+
methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
776
|
+
headers: allowHeaders = ["Content-Type", "Authorization"],
|
|
777
|
+
credentials = false,
|
|
778
|
+
maxAge = 86400
|
|
779
|
+
} = options;
|
|
780
|
+
const corsHeaders = {
|
|
781
|
+
"Access-Control-Allow-Origin": origin,
|
|
782
|
+
"Access-Control-Allow-Methods": methods.join(", "),
|
|
783
|
+
"Access-Control-Allow-Headers": allowHeaders.join(", "),
|
|
784
|
+
"Access-Control-Max-Age": String(maxAge)
|
|
785
|
+
};
|
|
786
|
+
if (credentials) corsHeaders["Access-Control-Allow-Credentials"] = "true";
|
|
787
|
+
return corsHeaders;
|
|
788
|
+
},
|
|
789
|
+
cache(options = {}) {
|
|
790
|
+
if (options.noStore) {
|
|
791
|
+
return { "Cache-Control": "no-store, no-cache, must-revalidate" };
|
|
792
|
+
}
|
|
793
|
+
const directives = [];
|
|
794
|
+
directives.push(options.private ? "private" : "public");
|
|
795
|
+
if (options.maxAge !== void 0) directives.push(`max-age=${options.maxAge}`);
|
|
796
|
+
if (options.sMaxAge !== void 0) directives.push(`s-maxage=${options.sMaxAge}`);
|
|
797
|
+
if (options.staleWhileRevalidate !== void 0) directives.push(`stale-while-revalidate=${options.staleWhileRevalidate}`);
|
|
798
|
+
return { "Cache-Control": directives.join(", ") };
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
async function parseJson(request) {
|
|
802
|
+
try {
|
|
803
|
+
return await request.json();
|
|
804
|
+
} catch {
|
|
805
|
+
throw new Error("Invalid JSON body");
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
async function parseFormData(request) {
|
|
809
|
+
return await request.formData();
|
|
810
|
+
}
|
|
811
|
+
function parseSearchParams(request) {
|
|
812
|
+
return new URL(request.url).searchParams;
|
|
813
|
+
}
|
|
814
|
+
function getMethod(request) {
|
|
815
|
+
return request.method.toUpperCase();
|
|
816
|
+
}
|
|
817
|
+
function getPathname(request) {
|
|
818
|
+
return new URL(request.url).pathname;
|
|
819
|
+
}
|
|
820
|
+
function isMethod(request, method) {
|
|
821
|
+
const reqMethod = getMethod(request);
|
|
822
|
+
return Array.isArray(method) ? method.map((m) => m.toUpperCase()).includes(reqMethod) : reqMethod === method.toUpperCase();
|
|
823
|
+
}
|
|
824
|
+
globalThis.__VELIX_ACTIONS__ = globalThis.__VELIX_ACTIONS__ || {};
|
|
825
|
+
globalThis.__VELIX_ACTION_CONTEXT__ = null;
|
|
826
|
+
function serverAction(fn, actionId) {
|
|
827
|
+
const id = actionId || `action_${fn.name}_${generateActionId()}`;
|
|
828
|
+
globalThis.__VELIX_ACTIONS__[id] = fn;
|
|
829
|
+
const proxy = (async (...args) => {
|
|
830
|
+
if (typeof window === "undefined") return await executeAction(id, args);
|
|
831
|
+
return await callServerAction(id, args);
|
|
832
|
+
});
|
|
833
|
+
proxy.$$typeof = /* @__PURE__ */ Symbol.for("react.server.action");
|
|
834
|
+
proxy.$$id = id;
|
|
835
|
+
proxy.$$bound = null;
|
|
836
|
+
return proxy;
|
|
837
|
+
}
|
|
838
|
+
function registerAction(id, fn) {
|
|
839
|
+
globalThis.__VELIX_ACTIONS__[id] = fn;
|
|
840
|
+
}
|
|
841
|
+
function getAction(id) {
|
|
842
|
+
return globalThis.__VELIX_ACTIONS__[id];
|
|
843
|
+
}
|
|
844
|
+
async function executeAction(actionId, args, context) {
|
|
845
|
+
const action = globalThis.__VELIX_ACTIONS__[actionId];
|
|
846
|
+
if (!action) return { success: false, error: `Server action not found: ${actionId}` };
|
|
847
|
+
const actionContext = {
|
|
848
|
+
request: context?.request || new Request("http://localhost"),
|
|
849
|
+
cookies,
|
|
850
|
+
headers,
|
|
851
|
+
redirect,
|
|
852
|
+
notFound
|
|
853
|
+
};
|
|
854
|
+
globalThis.__VELIX_ACTION_CONTEXT__ = actionContext;
|
|
855
|
+
try {
|
|
856
|
+
const result = await action(...args);
|
|
857
|
+
return { success: true, data: result };
|
|
858
|
+
} catch (error) {
|
|
859
|
+
if (error instanceof RedirectError) return { success: true, redirect: error.url };
|
|
860
|
+
if (error instanceof NotFoundError) return { success: false, error: "Not found" };
|
|
861
|
+
return { success: false, error: error.message || "Action failed" };
|
|
862
|
+
} finally {
|
|
863
|
+
globalThis.__VELIX_ACTION_CONTEXT__ = null;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
async function callServerAction(actionId, args) {
|
|
867
|
+
try {
|
|
868
|
+
const response = await fetch("/__velix/action", {
|
|
869
|
+
method: "POST",
|
|
870
|
+
headers: { "Content-Type": "application/json", "X-Velix-Action": actionId },
|
|
871
|
+
body: JSON.stringify({ actionId, args: serializeArgs(args) }),
|
|
872
|
+
credentials: "same-origin"
|
|
873
|
+
});
|
|
874
|
+
if (!response.ok) throw new Error(`Action failed: ${response.statusText}`);
|
|
875
|
+
const result = await response.json();
|
|
876
|
+
if (result.redirect) {
|
|
877
|
+
window.location.href = result.redirect;
|
|
878
|
+
}
|
|
879
|
+
return result;
|
|
880
|
+
} catch (error) {
|
|
881
|
+
return { success: false, error: error.message || "Network error" };
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function serializeArgs(args) {
|
|
885
|
+
return args.map((arg) => {
|
|
886
|
+
if (arg instanceof FormData) {
|
|
887
|
+
const obj = {};
|
|
888
|
+
arg.forEach((value, key) => {
|
|
889
|
+
if (obj[key]) {
|
|
890
|
+
obj[key] = Array.isArray(obj[key]) ? [...obj[key], value] : [obj[key], value];
|
|
891
|
+
} else {
|
|
892
|
+
obj[key] = value;
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
return { $$type: "FormData", data: obj };
|
|
896
|
+
}
|
|
897
|
+
if (arg instanceof Date) return { $$type: "Date", value: arg.toISOString() };
|
|
898
|
+
if (typeof arg === "object" && arg !== null) return JSON.parse(JSON.stringify(arg));
|
|
899
|
+
return arg;
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
var ALLOWED_TYPES = /* @__PURE__ */ new Set(["FormData", "Date", "File"]);
|
|
903
|
+
var MAX_DEPTH = 10;
|
|
904
|
+
function validateInput(obj, depth = 0) {
|
|
905
|
+
if (depth > MAX_DEPTH) throw new Error("Payload too deeply nested");
|
|
906
|
+
if (obj === null || obj === void 0 || typeof obj !== "object") return true;
|
|
907
|
+
if ("__proto__" in obj || "constructor" in obj || "prototype" in obj) {
|
|
908
|
+
throw new Error("Invalid payload: prototype pollution attempt detected");
|
|
909
|
+
}
|
|
910
|
+
if ("$$type" in obj && !ALLOWED_TYPES.has(obj.$$type)) {
|
|
911
|
+
throw new Error(`Invalid serialized type: ${obj.$$type}`);
|
|
912
|
+
}
|
|
913
|
+
if (Array.isArray(obj)) obj.forEach((item) => validateInput(item, depth + 1));
|
|
914
|
+
else Object.values(obj).forEach((val) => validateInput(val, depth + 1));
|
|
915
|
+
return true;
|
|
916
|
+
}
|
|
917
|
+
function deserializeArgs(args) {
|
|
918
|
+
validateInput(args);
|
|
919
|
+
return args.map((arg) => {
|
|
920
|
+
if (arg && typeof arg === "object") {
|
|
921
|
+
if (arg.$$type === "FormData") {
|
|
922
|
+
const fd = new FormData();
|
|
923
|
+
for (const [key, value] of Object.entries(arg.data || {})) {
|
|
924
|
+
if (typeof key !== "string" || key.startsWith("__")) continue;
|
|
925
|
+
if (Array.isArray(value)) value.forEach((v) => {
|
|
926
|
+
if (typeof v === "string" || typeof v === "number") fd.append(key, String(v));
|
|
927
|
+
});
|
|
928
|
+
else if (typeof value === "string" || typeof value === "number") fd.append(key, String(value));
|
|
929
|
+
}
|
|
930
|
+
return fd;
|
|
931
|
+
}
|
|
932
|
+
if (arg.$$type === "Date") {
|
|
933
|
+
const d = new Date(arg.value);
|
|
934
|
+
if (isNaN(d.getTime())) throw new Error("Invalid date");
|
|
935
|
+
return d;
|
|
936
|
+
}
|
|
937
|
+
if (arg.$$type === "File") return { name: String(arg.name || ""), type: String(arg.type || ""), size: Number(arg.size || 0) };
|
|
938
|
+
}
|
|
939
|
+
return arg;
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
function generateActionId() {
|
|
943
|
+
return Math.random().toString(36).substring(2, 10);
|
|
944
|
+
}
|
|
945
|
+
function useActionContext() {
|
|
946
|
+
return globalThis.__VELIX_ACTION_CONTEXT__;
|
|
947
|
+
}
|
|
948
|
+
function formAction(action) {
|
|
949
|
+
return async (formData) => {
|
|
950
|
+
try {
|
|
951
|
+
const result = await action(formData);
|
|
952
|
+
return { success: true, data: result };
|
|
953
|
+
} catch (error) {
|
|
954
|
+
if (error instanceof RedirectError) return { success: true, redirect: error.url };
|
|
955
|
+
return { success: false, error: error.message };
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
function useVelixAction(action, initialState, permalink) {
|
|
960
|
+
return useActionState(action, initialState, permalink);
|
|
961
|
+
}
|
|
962
|
+
function bindArgs(action, ...boundArgs) {
|
|
963
|
+
const bound = (async (...args) => await action(...boundArgs, ...args));
|
|
964
|
+
bound.$$typeof = action.$$typeof;
|
|
965
|
+
bound.$$id = action.$$id;
|
|
966
|
+
bound.$$bound = boundArgs;
|
|
967
|
+
return bound;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// server/devtools.ts
|
|
971
|
+
function generateDevToolsHtml(isDev) {
|
|
972
|
+
if (!isDev) return "";
|
|
973
|
+
return `<style>
|
|
974
|
+
@keyframes velix-pulse {
|
|
975
|
+
0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.7); }
|
|
976
|
+
70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(34, 211, 238, 0); }
|
|
977
|
+
100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
@keyframes velix-spin {
|
|
981
|
+
from { transform: rotate(0deg); }
|
|
982
|
+
to { transform: rotate(360deg); }
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
.velix-idle { background: #0f172a !important; border: 2px solid #22D3EE !important; }
|
|
986
|
+
.velix-rendering { background: #ea580c !important; border: 2px solid #fb923c !important; animation: velix-pulse 1.5s infinite !important; }
|
|
987
|
+
.velix-compiling { background: #16a34a !important; border: 2px solid #4ade80 !important; animation: velix-spin 2s linear infinite !important; }
|
|
988
|
+
.velix-navigating { background: #2563eb !important; border: 2px solid #60a5fa !important; animation: velix-pulse 1s infinite !important; }
|
|
989
|
+
.velix-error { background: #dc2626 !important; border: 2px solid #f87171 !important; animation: velix-pulse 0.8s infinite !important; }
|
|
990
|
+
|
|
991
|
+
.velix-status-badge {
|
|
992
|
+
position: absolute;
|
|
993
|
+
top: -4px;
|
|
994
|
+
right: -4px;
|
|
995
|
+
width: 12px;
|
|
996
|
+
height: 12px;
|
|
997
|
+
border-radius: 50%;
|
|
998
|
+
border: 2px solid #0f172a;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
.velix-status-idle { background: #22D3EE; }
|
|
1002
|
+
.velix-status-rendering { background: #fb923c; }
|
|
1003
|
+
.velix-status-compiling { background: #4ade80; }
|
|
1004
|
+
.velix-status-navigating { background: #60a5fa; }
|
|
1005
|
+
.velix-status-error { background: #f87171; }
|
|
1006
|
+
</style>
|
|
1007
|
+
|
|
1008
|
+
<script>
|
|
1009
|
+
// DevTools State Management
|
|
1010
|
+
window.__VELIX_DEV_TOOLS__ = {
|
|
1011
|
+
status: 'idle',
|
|
1012
|
+
setStatus: function(newStatus) {
|
|
1013
|
+
this.status = newStatus;
|
|
1014
|
+
const widget = document.getElementById('__velix-dev-tools');
|
|
1015
|
+
const badge = document.getElementById('__velix-status-badge');
|
|
1016
|
+
const statusText = document.getElementById('__velix-status-text');
|
|
1017
|
+
|
|
1018
|
+
if (widget) {
|
|
1019
|
+
widget.className = 'velix-' + newStatus;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if (badge) {
|
|
1023
|
+
badge.className = 'velix-status-badge velix-status-' + newStatus;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
if (statusText) {
|
|
1027
|
+
const statusLabels = {
|
|
1028
|
+
idle: 'Ready',
|
|
1029
|
+
rendering: 'Rendering',
|
|
1030
|
+
compiling: 'Compiling',
|
|
1031
|
+
navigating: 'Navigating',
|
|
1032
|
+
error: 'Error'
|
|
1033
|
+
};
|
|
1034
|
+
statusText.textContent = statusLabels[newStatus] || 'Unknown';
|
|
1035
|
+
statusText.style.color = {
|
|
1036
|
+
idle: '#22D3EE',
|
|
1037
|
+
rendering: '#fb923c',
|
|
1038
|
+
compiling: '#4ade80',
|
|
1039
|
+
navigating: '#60a5fa',
|
|
1040
|
+
error: '#f87171'
|
|
1041
|
+
}[newStatus] || '#94a3b8';
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
// HMR Connection
|
|
1047
|
+
const es = new EventSource('/__velix/hmr');
|
|
1048
|
+
es.onmessage = (e) => {
|
|
1049
|
+
const data = e.data;
|
|
1050
|
+
|
|
1051
|
+
if (data === 'reload') {
|
|
1052
|
+
window.__VELIX_DEV_TOOLS__.setStatus('idle');
|
|
1053
|
+
setTimeout(() => location.reload(), 100);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
if (data === 'building') {
|
|
1057
|
+
window.__VELIX_DEV_TOOLS__.setStatus('compiling');
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
if (data === 'built') {
|
|
1061
|
+
window.__VELIX_DEV_TOOLS__.setStatus('idle');
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
if (data.startsWith('rendering:')) {
|
|
1065
|
+
window.__VELIX_DEV_TOOLS__.setStatus('rendering');
|
|
1066
|
+
setTimeout(() => window.__VELIX_DEV_TOOLS__.setStatus('idle'), 1000);
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
if (data.startsWith('error:')) {
|
|
1070
|
+
window.__VELIX_DEV_TOOLS__.setStatus('error');
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
es.onerror = () => {
|
|
1075
|
+
window.__VELIX_DEV_TOOLS__.setStatus('error');
|
|
1076
|
+
};
|
|
1077
|
+
</script>
|
|
1078
|
+
|
|
1079
|
+
<div id="__velix-dev-tools" class="velix-idle" style="position:fixed;bottom:16px;left:16px;z-index:9999;border-radius:50%;padding:4px;box-shadow:0 4px 12px rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;width:40px;height:40px;cursor:pointer;transition:all 0.3s ease;" onmouseover="this.style.transform='scale(1.1)'" onmouseout="this.style.transform='scale(1)'" onclick="document.getElementById('__velix-dev-panel').style.display='block'" title="Velix DevTools">
|
|
1080
|
+
<img src="/__velix/logo.webp" alt="Velix DevTools" style="width:22px;height:22px;" />
|
|
1081
|
+
<div id="__velix-status-badge" class="velix-status-badge velix-status-idle"></div>
|
|
1082
|
+
</div>
|
|
1083
|
+
|
|
1084
|
+
<div id="__velix-dev-panel" style="display:none;position:fixed;bottom:70px;left:16px;width:320px;background:#0f172a;color:white;border-radius:16px;padding:20px;font-family:ui-sans-serif,system-ui,-apple-system,sans-serif;box-shadow:0 20px 50px rgba(0,0,0,0.4);z-index:10000;border:1px solid #1e293b;">
|
|
1085
|
+
<div style="display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #334155;padding-bottom:16px;margin-bottom:16px;">
|
|
1086
|
+
<h3 style="margin:0;font-size:16px;font-weight:700;display:flex;align-items:center;gap:10px;">
|
|
1087
|
+
<img src="/__velix/logo.webp" style="width:18px;height:18px;" />
|
|
1088
|
+
Velix DevTools
|
|
1089
|
+
</h3>
|
|
1090
|
+
<button onclick="document.getElementById('__velix-dev-panel').style.display='none'" style="background:transparent;border:none;color:#94a3b8;cursor:pointer;font-size:22px;line-height:1;padding:0;margin:0;transition:color 0.2s;" onmouseover="this.style.color='white'" onmouseout="this.style.color='#94a3b8'">×</button>
|
|
1091
|
+
</div>
|
|
1092
|
+
|
|
1093
|
+
<div style="margin-bottom:16px;padding:12px;background:#1e293b;border-radius:8px;border:1px solid #334155;">
|
|
1094
|
+
<div style="font-size:12px;color:#94a3b8;margin-bottom:4px;text-transform:uppercase;letter-spacing:0.5px;">Status</div>
|
|
1095
|
+
<div id="__velix-status-text" style="font-size:16px;font-weight:600;color:#22D3EE;">Ready</div>
|
|
1096
|
+
</div>
|
|
1097
|
+
|
|
1098
|
+
<div style="font-size:13px;color:#cbd5e1;line-height:2;">
|
|
1099
|
+
<div style="display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid #1e293b;">
|
|
1100
|
+
<span style="color:#94a3b8;">Framework</span>
|
|
1101
|
+
<strong style="color:white;font-weight:600;">v5.0.0</strong>
|
|
1102
|
+
</div>
|
|
1103
|
+
<div style="display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid #1e293b;">
|
|
1104
|
+
<span style="color:#94a3b8;">Environment</span>
|
|
1105
|
+
<strong style="color:#10b981;font-weight:600;">Development</strong>
|
|
1106
|
+
</div>
|
|
1107
|
+
<div style="display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid #1e293b;">
|
|
1108
|
+
<span style="color:#94a3b8;">Router</span>
|
|
1109
|
+
<strong style="color:white;font-weight:600;">App Directory</strong>
|
|
1110
|
+
</div>
|
|
1111
|
+
<div style="display:flex;justify-content:space-between;padding:8px 0;">
|
|
1112
|
+
<span style="color:#94a3b8;">Rendering</span>
|
|
1113
|
+
<strong style="color:#60a5fa;font-weight:600;">Streaming SSR</strong>
|
|
1114
|
+
</div>
|
|
1115
|
+
</div>
|
|
1116
|
+
|
|
1117
|
+
<div style="margin-top:16px;padding-top:16px;border-top:1px solid #334155;">
|
|
1118
|
+
<div style="font-size:11px;color:#64748b;text-align:center;">
|
|
1119
|
+
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#22D3EE;margin-right:4px;"></span> Idle
|
|
1120
|
+
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#fb923c;margin:0 4px 0 12px;"></span> Rendering
|
|
1121
|
+
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#4ade80;margin:0 4px 0 12px;"></span> Compiling
|
|
1122
|
+
</div>
|
|
1123
|
+
</div>
|
|
1124
|
+
</div>`;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// server/error-pages.ts
|
|
1128
|
+
function generate404Page(pathname = "/") {
|
|
1129
|
+
return `<!DOCTYPE html>
|
|
1130
|
+
<html lang="en">
|
|
1131
|
+
<head>
|
|
1132
|
+
<meta charset="UTF-8">
|
|
1133
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1134
|
+
<title>404 - Page Not Found | Velix v5</title>
|
|
1135
|
+
<style>
|
|
1136
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
1137
|
+
body {
|
|
1138
|
+
margin: 0;
|
|
1139
|
+
background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
|
|
1140
|
+
color: white;
|
|
1141
|
+
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1142
|
+
display: flex;
|
|
1143
|
+
align-items: center;
|
|
1144
|
+
justify-content: center;
|
|
1145
|
+
min-height: 100vh;
|
|
1146
|
+
text-align: center;
|
|
1147
|
+
overflow: hidden;
|
|
1148
|
+
}
|
|
1149
|
+
.container {
|
|
1150
|
+
max-width: 700px;
|
|
1151
|
+
padding: 60px 40px;
|
|
1152
|
+
position: relative;
|
|
1153
|
+
z-index: 10;
|
|
1154
|
+
}
|
|
1155
|
+
.bg-pattern {
|
|
1156
|
+
position: absolute;
|
|
1157
|
+
inset: 0;
|
|
1158
|
+
background-image: radial-gradient(circle at 20% 50%, rgba(34, 211, 238, 0.1) 0%, transparent 50%),
|
|
1159
|
+
radial-gradient(circle at 80% 80%, rgba(37, 99, 235, 0.1) 0%, transparent 50%);
|
|
1160
|
+
z-index: 1;
|
|
1161
|
+
}
|
|
1162
|
+
h1 {
|
|
1163
|
+
font-size: 180px;
|
|
1164
|
+
font-weight: 900;
|
|
1165
|
+
margin: 0;
|
|
1166
|
+
background: linear-gradient(135deg, #22D3EE 0%, #2563EB 100%);
|
|
1167
|
+
-webkit-background-clip: text;
|
|
1168
|
+
-webkit-text-fill-color: transparent;
|
|
1169
|
+
line-height: 1;
|
|
1170
|
+
letter-spacing: -0.05em;
|
|
1171
|
+
animation: fadeInUp 0.6s ease-out;
|
|
1172
|
+
}
|
|
1173
|
+
h2 {
|
|
1174
|
+
font-size: 36px;
|
|
1175
|
+
font-weight: 800;
|
|
1176
|
+
margin: 30px 0 15px;
|
|
1177
|
+
color: #F8FAFC;
|
|
1178
|
+
animation: fadeInUp 0.6s ease-out 0.1s backwards;
|
|
1179
|
+
}
|
|
1180
|
+
p {
|
|
1181
|
+
color: #94A3B8;
|
|
1182
|
+
font-size: 18px;
|
|
1183
|
+
line-height: 1.7;
|
|
1184
|
+
margin-bottom: 40px;
|
|
1185
|
+
animation: fadeInUp 0.6s ease-out 0.2s backwards;
|
|
1186
|
+
}
|
|
1187
|
+
code {
|
|
1188
|
+
background: rgba(255,255,255,0.1);
|
|
1189
|
+
padding: 4px 10px;
|
|
1190
|
+
border-radius: 6px;
|
|
1191
|
+
font-family: 'Fira Code', 'Courier New', monospace;
|
|
1192
|
+
color: #22D3EE;
|
|
1193
|
+
font-size: 16px;
|
|
1194
|
+
border: 1px solid rgba(34, 211, 238, 0.2);
|
|
1195
|
+
}
|
|
1196
|
+
.btn-group {
|
|
1197
|
+
display: flex;
|
|
1198
|
+
gap: 16px;
|
|
1199
|
+
justify-content: center;
|
|
1200
|
+
flex-wrap: wrap;
|
|
1201
|
+
animation: fadeInUp 0.6s ease-out 0.3s backwards;
|
|
1202
|
+
}
|
|
1203
|
+
.btn {
|
|
1204
|
+
display: inline-block;
|
|
1205
|
+
background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
|
|
1206
|
+
color: white;
|
|
1207
|
+
text-decoration: none;
|
|
1208
|
+
padding: 14px 36px;
|
|
1209
|
+
border-radius: 12px;
|
|
1210
|
+
font-weight: 600;
|
|
1211
|
+
font-size: 16px;
|
|
1212
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
1213
|
+
box-shadow: 0 10px 30px rgba(37, 99, 235, 0.3);
|
|
1214
|
+
border: none;
|
|
1215
|
+
cursor: pointer;
|
|
1216
|
+
}
|
|
1217
|
+
.btn:hover {
|
|
1218
|
+
transform: translateY(-2px);
|
|
1219
|
+
box-shadow: 0 15px 40px rgba(37, 99, 235, 0.4);
|
|
1220
|
+
}
|
|
1221
|
+
.btn-outline {
|
|
1222
|
+
background: transparent;
|
|
1223
|
+
color: #22D3EE;
|
|
1224
|
+
border: 2px solid #22D3EE;
|
|
1225
|
+
box-shadow: none;
|
|
1226
|
+
}
|
|
1227
|
+
.btn-outline:hover {
|
|
1228
|
+
background: rgba(34, 211, 238, 0.1);
|
|
1229
|
+
box-shadow: 0 10px 30px rgba(34, 211, 238, 0.2);
|
|
1230
|
+
}
|
|
1231
|
+
@keyframes fadeInUp {
|
|
1232
|
+
from {
|
|
1233
|
+
opacity: 0;
|
|
1234
|
+
transform: translateY(30px);
|
|
1235
|
+
}
|
|
1236
|
+
to {
|
|
1237
|
+
opacity: 1;
|
|
1238
|
+
transform: translateY(0);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
</style>
|
|
1242
|
+
</head>
|
|
1243
|
+
<body>
|
|
1244
|
+
<div class="bg-pattern"></div>
|
|
1245
|
+
<div class="container">
|
|
1246
|
+
<h1>404</h1>
|
|
1247
|
+
<h2>Page Not Found</h2>
|
|
1248
|
+
<p>The page <code>${pathname}</code> could not be found.<br>It may have been moved or deleted.</p>
|
|
1249
|
+
<div class="btn-group">
|
|
1250
|
+
<a href="/" class="btn">Return Home</a>
|
|
1251
|
+
<a href="javascript:history.back()" class="btn btn-outline">Go Back</a>
|
|
1252
|
+
</div>
|
|
1253
|
+
</div>
|
|
1254
|
+
</body>
|
|
1255
|
+
</html>`;
|
|
1256
|
+
}
|
|
1257
|
+
function generate500Page(options) {
|
|
1258
|
+
const { title, message, stack, isDev, pathname } = options;
|
|
1259
|
+
let callStackCards = "";
|
|
1260
|
+
let frameCount = 0;
|
|
1261
|
+
if (isDev && stack) {
|
|
1262
|
+
const stackLines = stack.split("\n").filter((line) => line.trim());
|
|
1263
|
+
const frames = stackLines.slice(1).filter((line) => line.includes("at "));
|
|
1264
|
+
frameCount = frames.length;
|
|
1265
|
+
callStackCards = frames.map((frame, index) => {
|
|
1266
|
+
const match = frame.match(/at\s+(.+?)\s+\((.+?)\)/) || frame.match(/at\s+(.+)/);
|
|
1267
|
+
if (match) {
|
|
1268
|
+
const funcName = match[1] || "anonymous";
|
|
1269
|
+
const location = match[2] || match[1];
|
|
1270
|
+
return `
|
|
1271
|
+
<div class="error-card" data-frame="${index}">
|
|
1272
|
+
<div class="card-header">
|
|
1273
|
+
<div class="card-title">${funcName.trim()}</div>
|
|
1274
|
+
<div class="card-number">${index + 1}</div>
|
|
1275
|
+
</div>
|
|
1276
|
+
<div class="card-location">${location.trim()}</div>
|
|
1277
|
+
</div>
|
|
1278
|
+
`;
|
|
1279
|
+
}
|
|
1280
|
+
return "";
|
|
1281
|
+
}).join("");
|
|
1282
|
+
}
|
|
1283
|
+
return `<!DOCTYPE html>
|
|
1284
|
+
<html lang="en">
|
|
1285
|
+
<head>
|
|
1286
|
+
<meta charset="UTF-8">
|
|
1287
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1288
|
+
<title>Error | Velix v5</title>
|
|
1289
|
+
<style>
|
|
1290
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
1291
|
+
body {
|
|
1292
|
+
margin: 0;
|
|
1293
|
+
background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
|
|
1294
|
+
color: #F8FAFC;
|
|
1295
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
1296
|
+
min-height: 100vh;
|
|
1297
|
+
overflow-x: hidden;
|
|
1298
|
+
}
|
|
1299
|
+
.container {
|
|
1300
|
+
max-width: 900px;
|
|
1301
|
+
margin: 0 auto;
|
|
1302
|
+
padding: 40px 20px;
|
|
1303
|
+
}
|
|
1304
|
+
.error-header {
|
|
1305
|
+
background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
|
|
1306
|
+
color: white;
|
|
1307
|
+
padding: 20px 28px;
|
|
1308
|
+
border-radius: 16px;
|
|
1309
|
+
display: flex;
|
|
1310
|
+
align-items: center;
|
|
1311
|
+
gap: 14px;
|
|
1312
|
+
margin-bottom: 28px;
|
|
1313
|
+
font-size: 18px;
|
|
1314
|
+
font-weight: 700;
|
|
1315
|
+
box-shadow: 0 10px 40px rgba(239, 68, 68, 0.3);
|
|
1316
|
+
}
|
|
1317
|
+
.error-header svg {
|
|
1318
|
+
width: 24px;
|
|
1319
|
+
height: 24px;
|
|
1320
|
+
flex-shrink: 0;
|
|
1321
|
+
}
|
|
1322
|
+
.error-badge {
|
|
1323
|
+
display: inline-block;
|
|
1324
|
+
background: linear-gradient(135deg, #1E40AF 0%, #1E3A8A 100%);
|
|
1325
|
+
color: #60A5FA;
|
|
1326
|
+
padding: 6px 16px;
|
|
1327
|
+
border-radius: 8px;
|
|
1328
|
+
font-size: 13px;
|
|
1329
|
+
font-weight: 700;
|
|
1330
|
+
margin-bottom: 18px;
|
|
1331
|
+
text-transform: uppercase;
|
|
1332
|
+
letter-spacing: 0.8px;
|
|
1333
|
+
box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
|
|
1334
|
+
}
|
|
1335
|
+
.route-badge {
|
|
1336
|
+
background: linear-gradient(135deg, #0C4A6E 0%, #075985 100%);
|
|
1337
|
+
color: #22D3EE;
|
|
1338
|
+
padding: 10px 18px;
|
|
1339
|
+
border-radius: 10px;
|
|
1340
|
+
font-size: 14px;
|
|
1341
|
+
margin-bottom: 24px;
|
|
1342
|
+
font-family: 'Courier New', monospace;
|
|
1343
|
+
box-shadow: 0 4px 12px rgba(12, 74, 110, 0.3);
|
|
1344
|
+
border: 1px solid rgba(34, 211, 238, 0.2);
|
|
1345
|
+
}
|
|
1346
|
+
.error-message {
|
|
1347
|
+
background: rgba(239, 68, 68, 0.1);
|
|
1348
|
+
border-left: 4px solid #EF4444;
|
|
1349
|
+
padding: 18px 20px;
|
|
1350
|
+
border-radius: 10px;
|
|
1351
|
+
margin-bottom: 32px;
|
|
1352
|
+
}
|
|
1353
|
+
.error-message-text {
|
|
1354
|
+
color: #FCA5A5;
|
|
1355
|
+
font-size: 16px;
|
|
1356
|
+
font-weight: 600;
|
|
1357
|
+
line-height: 1.6;
|
|
1358
|
+
font-family: 'Courier New', monospace;
|
|
1359
|
+
}
|
|
1360
|
+
.stack-section {
|
|
1361
|
+
margin-top: 32px;
|
|
1362
|
+
}
|
|
1363
|
+
.stack-header {
|
|
1364
|
+
display: flex;
|
|
1365
|
+
align-items: center;
|
|
1366
|
+
justify-content: space-between;
|
|
1367
|
+
margin-bottom: 20px;
|
|
1368
|
+
}
|
|
1369
|
+
.stack-title {
|
|
1370
|
+
font-size: 18px;
|
|
1371
|
+
font-weight: 700;
|
|
1372
|
+
color: #F1F5F9;
|
|
1373
|
+
display: flex;
|
|
1374
|
+
align-items: center;
|
|
1375
|
+
gap: 10px;
|
|
1376
|
+
}
|
|
1377
|
+
.frame-counter {
|
|
1378
|
+
background: linear-gradient(135deg, #1F2937 0%, #111827 100%);
|
|
1379
|
+
color: #22D3EE;
|
|
1380
|
+
padding: 6px 14px;
|
|
1381
|
+
border-radius: 8px;
|
|
1382
|
+
font-size: 13px;
|
|
1383
|
+
font-weight: 700;
|
|
1384
|
+
border: 1px solid rgba(34, 211, 238, 0.2);
|
|
1385
|
+
}
|
|
1386
|
+
.error-card {
|
|
1387
|
+
background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
|
|
1388
|
+
border: 1px solid rgba(34, 211, 238, 0.2);
|
|
1389
|
+
border-radius: 14px;
|
|
1390
|
+
padding: 20px;
|
|
1391
|
+
margin-bottom: 12px;
|
|
1392
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
1393
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
1394
|
+
display: none;
|
|
1395
|
+
}
|
|
1396
|
+
.error-card.active {
|
|
1397
|
+
display: block;
|
|
1398
|
+
animation: slideIn 0.3s ease-out;
|
|
1399
|
+
}
|
|
1400
|
+
.error-card:hover {
|
|
1401
|
+
border-color: rgba(34, 211, 238, 0.5);
|
|
1402
|
+
box-shadow: 0 8px 24px rgba(34, 211, 238, 0.2);
|
|
1403
|
+
transform: translateY(-2px);
|
|
1404
|
+
}
|
|
1405
|
+
.card-header {
|
|
1406
|
+
display: flex;
|
|
1407
|
+
justify-content: space-between;
|
|
1408
|
+
align-items: center;
|
|
1409
|
+
margin-bottom: 12px;
|
|
1410
|
+
}
|
|
1411
|
+
.card-title {
|
|
1412
|
+
color: #22D3EE;
|
|
1413
|
+
font-size: 15px;
|
|
1414
|
+
font-weight: 700;
|
|
1415
|
+
font-family: 'Courier New', monospace;
|
|
1416
|
+
}
|
|
1417
|
+
.card-number {
|
|
1418
|
+
background: rgba(34, 211, 238, 0.2);
|
|
1419
|
+
color: #22D3EE;
|
|
1420
|
+
padding: 4px 10px;
|
|
1421
|
+
border-radius: 6px;
|
|
1422
|
+
font-size: 12px;
|
|
1423
|
+
font-weight: 700;
|
|
1424
|
+
}
|
|
1425
|
+
.card-location {
|
|
1426
|
+
color: #94A3B8;
|
|
1427
|
+
font-size: 13px;
|
|
1428
|
+
font-family: 'Courier New', monospace;
|
|
1429
|
+
word-break: break-all;
|
|
1430
|
+
line-height: 1.6;
|
|
1431
|
+
}
|
|
1432
|
+
.pagination {
|
|
1433
|
+
display: flex;
|
|
1434
|
+
justify-content: center;
|
|
1435
|
+
align-items: center;
|
|
1436
|
+
gap: 12px;
|
|
1437
|
+
margin-top: 24px;
|
|
1438
|
+
}
|
|
1439
|
+
.pagination-btn {
|
|
1440
|
+
background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
|
|
1441
|
+
border: 1px solid rgba(34, 211, 238, 0.3);
|
|
1442
|
+
color: #22D3EE;
|
|
1443
|
+
padding: 10px 20px;
|
|
1444
|
+
border-radius: 10px;
|
|
1445
|
+
font-size: 14px;
|
|
1446
|
+
font-weight: 600;
|
|
1447
|
+
cursor: pointer;
|
|
1448
|
+
transition: all 0.2s;
|
|
1449
|
+
}
|
|
1450
|
+
.pagination-btn:hover:not(:disabled) {
|
|
1451
|
+
background: linear-gradient(135deg, #22D3EE 0%, #06B6D4 100%);
|
|
1452
|
+
color: #0F172A;
|
|
1453
|
+
transform: translateY(-2px);
|
|
1454
|
+
box-shadow: 0 6px 20px rgba(34, 211, 238, 0.4);
|
|
1455
|
+
}
|
|
1456
|
+
.pagination-btn:disabled {
|
|
1457
|
+
opacity: 0.3;
|
|
1458
|
+
cursor: not-allowed;
|
|
1459
|
+
}
|
|
1460
|
+
.pagination-info {
|
|
1461
|
+
color: #94A3B8;
|
|
1462
|
+
font-size: 14px;
|
|
1463
|
+
font-weight: 600;
|
|
1464
|
+
}
|
|
1465
|
+
.footer {
|
|
1466
|
+
margin-top: 48px;
|
|
1467
|
+
padding-top: 28px;
|
|
1468
|
+
border-top: 1px solid rgba(34, 211, 238, 0.2);
|
|
1469
|
+
display: flex;
|
|
1470
|
+
justify-content: space-between;
|
|
1471
|
+
align-items: center;
|
|
1472
|
+
flex-wrap: wrap;
|
|
1473
|
+
gap: 20px;
|
|
1474
|
+
}
|
|
1475
|
+
.brand {
|
|
1476
|
+
display: flex;
|
|
1477
|
+
align-items: center;
|
|
1478
|
+
gap: 10px;
|
|
1479
|
+
font-weight: 700;
|
|
1480
|
+
color: #22D3EE;
|
|
1481
|
+
font-size: 15px;
|
|
1482
|
+
}
|
|
1483
|
+
.brand img {
|
|
1484
|
+
width: 20px;
|
|
1485
|
+
height: 20px;
|
|
1486
|
+
}
|
|
1487
|
+
.footer-links {
|
|
1488
|
+
display: flex;
|
|
1489
|
+
gap: 24px;
|
|
1490
|
+
flex-wrap: wrap;
|
|
1491
|
+
}
|
|
1492
|
+
.footer-links a {
|
|
1493
|
+
color: #60A5FA;
|
|
1494
|
+
text-decoration: none;
|
|
1495
|
+
font-weight: 600;
|
|
1496
|
+
transition: all 0.2s;
|
|
1497
|
+
font-size: 14px;
|
|
1498
|
+
}
|
|
1499
|
+
.footer-links a:hover {
|
|
1500
|
+
color: #22D3EE;
|
|
1501
|
+
transform: translateY(-1px);
|
|
1502
|
+
}
|
|
1503
|
+
.no-stack {
|
|
1504
|
+
background: rgba(239, 68, 68, 0.1);
|
|
1505
|
+
border: 1px solid rgba(239, 68, 68, 0.3);
|
|
1506
|
+
border-radius: 12px;
|
|
1507
|
+
padding: 32px;
|
|
1508
|
+
color: #FCA5A5;
|
|
1509
|
+
text-align: center;
|
|
1510
|
+
font-size: 15px;
|
|
1511
|
+
}
|
|
1512
|
+
@keyframes slideIn {
|
|
1513
|
+
from {
|
|
1514
|
+
opacity: 0;
|
|
1515
|
+
transform: translateY(10px);
|
|
1516
|
+
}
|
|
1517
|
+
to {
|
|
1518
|
+
opacity: 1;
|
|
1519
|
+
transform: translateY(0);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
</style>
|
|
1523
|
+
</head>
|
|
1524
|
+
<body>
|
|
1525
|
+
<div class="container">
|
|
1526
|
+
<div class="error-header">
|
|
1527
|
+
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
1528
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>
|
|
1529
|
+
</svg>
|
|
1530
|
+
<span>Unhandled Runtime Error</span>
|
|
1531
|
+
</div>
|
|
1532
|
+
|
|
1533
|
+
<div class="error-badge">SERVER ERROR 500</div>
|
|
1534
|
+
${pathname ? `<div class="route-badge">Route: ${pathname}</div>` : ""}
|
|
1535
|
+
|
|
1536
|
+
<div class="error-message">
|
|
1537
|
+
<div class="error-message-text">${message}</div>
|
|
1538
|
+
</div>
|
|
1539
|
+
|
|
1540
|
+
${isDev && callStackCards ? `
|
|
1541
|
+
<div class="stack-section">
|
|
1542
|
+
<div class="stack-header">
|
|
1543
|
+
<div class="stack-title">
|
|
1544
|
+
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
1545
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
|
|
1546
|
+
</svg>
|
|
1547
|
+
Call Stack
|
|
1548
|
+
</div>
|
|
1549
|
+
<div class="frame-counter">${frameCount}</div>
|
|
1550
|
+
</div>
|
|
1551
|
+
<div id="error-cards">
|
|
1552
|
+
${callStackCards}
|
|
1553
|
+
</div>
|
|
1554
|
+
${frameCount > 1 ? `
|
|
1555
|
+
<div class="pagination">
|
|
1556
|
+
<button class="pagination-btn" id="prev-btn" onclick="changePage(-1)">
|
|
1557
|
+
<svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="display:inline;vertical-align:middle;margin-right:4px;">
|
|
1558
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
|
|
1559
|
+
</svg>
|
|
1560
|
+
Previous
|
|
1561
|
+
</button>
|
|
1562
|
+
<div class="pagination-info">
|
|
1563
|
+
<span id="current-page">1</span> / <span id="total-pages">${frameCount}</span>
|
|
1564
|
+
</div>
|
|
1565
|
+
<button class="pagination-btn" id="next-btn" onclick="changePage(1)">
|
|
1566
|
+
Next
|
|
1567
|
+
<svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="display:inline;vertical-align:middle;margin-left:4px;">
|
|
1568
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
|
|
1569
|
+
</svg>
|
|
1570
|
+
</button>
|
|
1571
|
+
</div>
|
|
1572
|
+
` : ""}
|
|
1573
|
+
</div>
|
|
1574
|
+
` : '<div class="no-stack">An error occurred while processing your request. Please check the server logs for more details.</div>'}
|
|
1575
|
+
|
|
1576
|
+
<div class="footer">
|
|
1577
|
+
<div class="brand">
|
|
1578
|
+
<img src="/__velix/logo.webp" alt="Velix" onerror="this.style.display='none'"/>
|
|
1579
|
+
<span>Velix v5.0.0</span>
|
|
1580
|
+
</div>
|
|
1581
|
+
<div class="footer-links">
|
|
1582
|
+
<a href="/">Home</a>
|
|
1583
|
+
<a href="javascript:location.reload()">Reload</a>
|
|
1584
|
+
<a href="https://github.com/velix/velix/tree/main/docs" target="_blank">Documentation</a>
|
|
1585
|
+
${isDev ? '<span style="color:#94A3B8;">Development Mode</span>' : ""}
|
|
1586
|
+
</div>
|
|
1587
|
+
</div>
|
|
1588
|
+
</div>
|
|
1589
|
+
|
|
1590
|
+
${isDev && frameCount > 0 ? `
|
|
1591
|
+
<script>
|
|
1592
|
+
let currentPage = 1;
|
|
1593
|
+
const totalPages = ${frameCount};
|
|
1594
|
+
const cards = document.querySelectorAll('.error-card');
|
|
1595
|
+
const prevBtn = document.getElementById('prev-btn');
|
|
1596
|
+
const nextBtn = document.getElementById('next-btn');
|
|
1597
|
+
const currentPageSpan = document.getElementById('current-page');
|
|
1598
|
+
|
|
1599
|
+
function showPage(page) {
|
|
1600
|
+
cards.forEach((card, index) => {
|
|
1601
|
+
card.classList.remove('active');
|
|
1602
|
+
if (index === page - 1) {
|
|
1603
|
+
card.classList.add('active');
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1607
|
+
currentPage = page;
|
|
1608
|
+
currentPageSpan.textContent = page;
|
|
1609
|
+
|
|
1610
|
+
if (prevBtn) prevBtn.disabled = page === 1;
|
|
1611
|
+
if (nextBtn) nextBtn.disabled = page === totalPages;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
function changePage(direction) {
|
|
1615
|
+
const newPage = currentPage + direction;
|
|
1616
|
+
if (newPage >= 1 && newPage <= totalPages) {
|
|
1617
|
+
showPage(newPage);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
// Show first page on load
|
|
1622
|
+
showPage(1);
|
|
1623
|
+
|
|
1624
|
+
// Keyboard navigation
|
|
1625
|
+
document.addEventListener('keydown', (e) => {
|
|
1626
|
+
if (e.key === 'ArrowLeft') changePage(-1);
|
|
1627
|
+
if (e.key === 'ArrowRight') changePage(1);
|
|
1628
|
+
});
|
|
1629
|
+
</script>
|
|
1630
|
+
` : ""}
|
|
1631
|
+
</body>
|
|
1632
|
+
</html>`;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// server/index.ts
|
|
1636
|
+
var MIME_TYPES = {
|
|
1637
|
+
".html": "text/html; charset=utf-8",
|
|
1638
|
+
".css": "text/css; charset=utf-8",
|
|
1639
|
+
".js": "application/javascript; charset=utf-8",
|
|
1640
|
+
".mjs": "application/javascript; charset=utf-8",
|
|
1641
|
+
".json": "application/json",
|
|
1642
|
+
".png": "image/png",
|
|
1643
|
+
".jpg": "image/jpeg",
|
|
1644
|
+
".jpeg": "image/jpeg",
|
|
1645
|
+
".gif": "image/gif",
|
|
1646
|
+
".svg": "image/svg+xml",
|
|
1647
|
+
".ico": "image/x-icon",
|
|
1648
|
+
".webp": "image/webp",
|
|
1649
|
+
".woff": "font/woff",
|
|
1650
|
+
".woff2": "font/woff2",
|
|
1651
|
+
".ttf": "font/ttf",
|
|
1652
|
+
".otf": "font/otf",
|
|
1653
|
+
".txt": "text/plain; charset=utf-8",
|
|
1654
|
+
".xml": "application/xml",
|
|
1655
|
+
".mp4": "video/mp4",
|
|
1656
|
+
".webm": "video/webm",
|
|
1657
|
+
".mp3": "audio/mpeg",
|
|
1658
|
+
".pdf": "application/pdf",
|
|
1659
|
+
".map": "application/json"
|
|
1660
|
+
};
|
|
1661
|
+
async function createServer(options = {}) {
|
|
1662
|
+
const projectRoot = options.projectRoot || process.cwd();
|
|
1663
|
+
const mode = options.mode || process.env.NODE_ENV || "development";
|
|
1664
|
+
const isDev = mode === "development";
|
|
1665
|
+
const rawConfig = await loadConfig(projectRoot);
|
|
1666
|
+
const config = resolvePaths(rawConfig, projectRoot);
|
|
1667
|
+
await loadPlugins(projectRoot, config);
|
|
1668
|
+
await pluginManager.runHook(PluginHooks.CONFIG, config);
|
|
1669
|
+
const middlewareFns = await loadMiddleware(projectRoot);
|
|
1670
|
+
const appDir = config.resolvedAppDir || path4.join(projectRoot, "app");
|
|
1671
|
+
const routes = buildRouteTree(appDir);
|
|
1672
|
+
await pluginManager.runHook(PluginHooks.ROUTES_LOADED, routes);
|
|
1673
|
+
const startTime = Date.now();
|
|
1674
|
+
await pluginManager.runHook(PluginHooks.SERVER_START, { config, isDev, projectRoot }, isDev);
|
|
1675
|
+
const server = http.createServer(async (req, res) => {
|
|
1676
|
+
const requestStart = Date.now();
|
|
1677
|
+
const url = new URL(req.url || "/", `http://${req.headers.host || "localhost"}`);
|
|
1678
|
+
const pathname = url.pathname;
|
|
1679
|
+
try {
|
|
1680
|
+
if (middlewareFns.length > 0) {
|
|
1681
|
+
const middlewareResult = await runMiddleware(req, res, middlewareFns);
|
|
1682
|
+
if (!middlewareResult.continue) return;
|
|
1683
|
+
}
|
|
1684
|
+
await pluginManager.runHook(PluginHooks.REQUEST, req, res);
|
|
1685
|
+
if (pathname === "/sitemap.xml" && config.seo.sitemap) {
|
|
1686
|
+
const baseUrl = config.app.url || `http://${config.server.host}:${config.server.port}`;
|
|
1687
|
+
const sitemap = generateSitemap(routes.appRoutes, baseUrl);
|
|
1688
|
+
res.writeHead(200, { "Content-Type": "application/xml" });
|
|
1689
|
+
res.end(sitemap);
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
if (pathname === "/robots.txt" && config.seo.robots) {
|
|
1693
|
+
const baseUrl = config.app.url || `http://${config.server.host}:${config.server.port}`;
|
|
1694
|
+
const robotsTxt = generateRobotsTxt(baseUrl);
|
|
1695
|
+
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
1696
|
+
res.end(robotsTxt);
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
if (pathname === "/__velix/action" && req.method === "POST") {
|
|
1700
|
+
await handleServerAction(req, res);
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1703
|
+
if (pathname === "/__velix/image") {
|
|
1704
|
+
const { handleImageOptimization } = await import('./image-optimizer-I6TWWH6W.js');
|
|
1705
|
+
await handleImageOptimization(req, res, projectRoot);
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1708
|
+
if (pathname.startsWith("/__velix/")) {
|
|
1709
|
+
await serveVelixInternal(pathname, req, res, projectRoot);
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const publicDir = config.resolvedPublicDir || path4.join(projectRoot, "public");
|
|
1713
|
+
if (await serveStaticFile(pathname, publicDir, res, isDev)) {
|
|
1714
|
+
if (isDev) logger_default.request(req.method || "GET", pathname, 200, Date.now() - requestStart, { type: "static" });
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
const apiMatch = matchRoute(pathname, routes.api);
|
|
1718
|
+
if (apiMatch) {
|
|
1719
|
+
await handleApiRoute(apiMatch, req, res, url);
|
|
1720
|
+
if (isDev) logger_default.request(req.method || "GET", pathname, res.statusCode, Date.now() - requestStart, { type: "api" });
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
const pageMatch = matchRoute(pathname, routes.appRoutes);
|
|
1724
|
+
if (pageMatch) {
|
|
1725
|
+
await handlePageRoute(pageMatch, routes, req, res, url, config, isDev, projectRoot);
|
|
1726
|
+
if (isDev) logger_default.request(req.method || "GET", pathname, res.statusCode, Date.now() - requestStart, { type: "ssr" });
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
res.writeHead(404, { "Content-Type": "text/html; charset=utf-8" });
|
|
1730
|
+
res.end(generate404Page(pathname));
|
|
1731
|
+
if (isDev) logger_default.request(req.method || "GET", pathname, 404, Date.now() - requestStart);
|
|
1732
|
+
} catch (error) {
|
|
1733
|
+
console.error("Server error:", error);
|
|
1734
|
+
if (!res.headersSent) {
|
|
1735
|
+
res.writeHead(500, { "Content-Type": "text/html; charset=utf-8" });
|
|
1736
|
+
res.end(generate500Page({
|
|
1737
|
+
title: "Server Error",
|
|
1738
|
+
message: error.message || "An unexpected error occurred",
|
|
1739
|
+
stack: isDev ? error.stack : void 0,
|
|
1740
|
+
isDev,
|
|
1741
|
+
pathname
|
|
1742
|
+
}));
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
});
|
|
1746
|
+
const __hmrClients = /* @__PURE__ */ new Set();
|
|
1747
|
+
server.__hmrClients = __hmrClients;
|
|
1748
|
+
server.broadcastHMR = (msg) => {
|
|
1749
|
+
__hmrClients.forEach((c) => c.write(`data: ${msg}
|
|
1750
|
+
|
|
1751
|
+
`));
|
|
1752
|
+
};
|
|
1753
|
+
const port = config.server.port;
|
|
1754
|
+
const host = config.server.host;
|
|
1755
|
+
server.listen(port, host, () => {
|
|
1756
|
+
logger_default.serverStart({ port, host, mode, pagesDir: appDir }, startTime);
|
|
1757
|
+
if (isDev) {
|
|
1758
|
+
routes.appRoutes.forEach((r) => {
|
|
1759
|
+
const type = r.path.includes(":") || r.path.includes("*") ? "dynamic" : "static";
|
|
1760
|
+
logger_default.route(r.path, type);
|
|
1761
|
+
});
|
|
1762
|
+
routes.api.forEach((r) => logger_default.route(r.path, "api"));
|
|
1763
|
+
logger_default.blank();
|
|
1764
|
+
}
|
|
1765
|
+
});
|
|
1766
|
+
server.on("error", (err) => {
|
|
1767
|
+
if (err.code === "EADDRINUSE") {
|
|
1768
|
+
logger_default.portInUse(port);
|
|
1769
|
+
process.exit(1);
|
|
1770
|
+
}
|
|
1771
|
+
throw err;
|
|
1772
|
+
});
|
|
1773
|
+
return {
|
|
1774
|
+
server,
|
|
1775
|
+
config: rawConfig,
|
|
1776
|
+
close: () => server.close()
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
async function serveStaticFile(pathname, publicDir, res, isDev = false) {
|
|
1780
|
+
const filePath = path4.join(publicDir, pathname);
|
|
1781
|
+
if (!filePath.startsWith(publicDir)) return false;
|
|
1782
|
+
if (!fs4.existsSync(filePath) || fs4.statSync(filePath).isDirectory()) return false;
|
|
1783
|
+
const ext = path4.extname(filePath);
|
|
1784
|
+
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
1785
|
+
const content = fs4.readFileSync(filePath);
|
|
1786
|
+
res.writeHead(200, {
|
|
1787
|
+
"Content-Type": contentType,
|
|
1788
|
+
"Content-Length": content.length,
|
|
1789
|
+
"Cache-Control": isDev ? "no-store, no-cache, must-revalidate" : "public, max-age=31536000, immutable"
|
|
1790
|
+
});
|
|
1791
|
+
res.end(content);
|
|
1792
|
+
return true;
|
|
1793
|
+
}
|
|
1794
|
+
async function handleApiRoute(route, req, res, url) {
|
|
1795
|
+
try {
|
|
1796
|
+
const fileUrl = pathToFileURL(route.filePath).href;
|
|
1797
|
+
const mod = await import(`${fileUrl}?t=${Date.now()}`);
|
|
1798
|
+
const method = req.method?.toUpperCase() || "GET";
|
|
1799
|
+
const handler = mod[method] || mod.default;
|
|
1800
|
+
if (!handler) {
|
|
1801
|
+
res.writeHead(405, { "Content-Type": "application/json" });
|
|
1802
|
+
res.end(JSON.stringify({ error: "Method not allowed" }));
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
let body;
|
|
1806
|
+
if (["POST", "PUT", "PATCH"].includes(method)) {
|
|
1807
|
+
body = await parseRequestBody(req);
|
|
1808
|
+
}
|
|
1809
|
+
const request = {
|
|
1810
|
+
method,
|
|
1811
|
+
url: req.url,
|
|
1812
|
+
headers: req.headers,
|
|
1813
|
+
params: route.params || {},
|
|
1814
|
+
query: Object.fromEntries(url.searchParams),
|
|
1815
|
+
body,
|
|
1816
|
+
json: () => body
|
|
1817
|
+
};
|
|
1818
|
+
const response = await handler(request);
|
|
1819
|
+
if (response instanceof Response) {
|
|
1820
|
+
const headers2 = {};
|
|
1821
|
+
response.headers.forEach((v, k) => {
|
|
1822
|
+
headers2[k] = v;
|
|
1823
|
+
});
|
|
1824
|
+
res.writeHead(response.status, headers2);
|
|
1825
|
+
const text2 = await response.text();
|
|
1826
|
+
res.end(text2);
|
|
1827
|
+
} else if (typeof response === "object") {
|
|
1828
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1829
|
+
res.end(JSON.stringify(response));
|
|
1830
|
+
} else {
|
|
1831
|
+
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
1832
|
+
res.end(String(response));
|
|
1833
|
+
}
|
|
1834
|
+
} catch (err) {
|
|
1835
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
1836
|
+
res.end(JSON.stringify({ error: err.message }));
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
async function handleServerAction(req, res) {
|
|
1840
|
+
try {
|
|
1841
|
+
const body = await parseRequestBody(req);
|
|
1842
|
+
if (!body?.actionId || typeof body.actionId !== "string") {
|
|
1843
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
1844
|
+
res.end(JSON.stringify({ error: "Missing actionId" }));
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
const args = body.args ? deserializeArgs(body.args) : [];
|
|
1848
|
+
const result = await executeAction(body.actionId, args);
|
|
1849
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1850
|
+
res.end(JSON.stringify(result));
|
|
1851
|
+
} catch (err) {
|
|
1852
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
1853
|
+
res.end(JSON.stringify({ success: false, error: err.message }));
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
async function handlePageRoute(route, routes, req, res, url, config, isDev, projectRoot) {
|
|
1857
|
+
try {
|
|
1858
|
+
const fileUrl = pathToFileURL(route.filePath).href;
|
|
1859
|
+
const mod = await import(`${fileUrl}?t=${Date.now()}`);
|
|
1860
|
+
const PageComponent = mod.default;
|
|
1861
|
+
let metadata = mod.metadata || mod.generateMetadata?.(route.params) || {};
|
|
1862
|
+
let LayoutComponent = ({ children }) => React.createElement(React.Fragment, null, children);
|
|
1863
|
+
let layoutParams = route.params;
|
|
1864
|
+
try {
|
|
1865
|
+
const layoutPath = path4.join(path4.dirname(route.filePath), "layout.tsx");
|
|
1866
|
+
if (fs4.existsSync(layoutPath)) {
|
|
1867
|
+
const layoutMod = await import(`${pathToFileURL(layoutPath).href}?t=${Date.now()}`);
|
|
1868
|
+
if (layoutMod.metadata) {
|
|
1869
|
+
metadata = { ...layoutMod.metadata, ...metadata };
|
|
1870
|
+
}
|
|
1871
|
+
if (layoutMod.default) {
|
|
1872
|
+
LayoutComponent = layoutMod.default;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
} catch (e) {
|
|
1876
|
+
}
|
|
1877
|
+
const baseUrl = config.app.url || `http://${config.server.host}:${config.server.port}`;
|
|
1878
|
+
const metaTags = generateMetadataTags({
|
|
1879
|
+
...metadata,
|
|
1880
|
+
generator: `Velix v5.0.0`,
|
|
1881
|
+
viewport: metadata.viewport || "width=device-width, initial-scale=1"
|
|
1882
|
+
}, baseUrl);
|
|
1883
|
+
const islands = getRegisteredIslands();
|
|
1884
|
+
const hydrationScript = generateAdvancedHydrationScript(islands);
|
|
1885
|
+
const devToolsHtml = generateDevToolsHtml(isDev);
|
|
1886
|
+
const headInjections = `
|
|
1887
|
+
<meta charset="utf-8">
|
|
1888
|
+
${metaTags}
|
|
1889
|
+
${config.favicon ? `<link rel="icon" href="${config.favicon}">` : ""}
|
|
1890
|
+
${config.styles.map((s) => `<link rel="stylesheet" href="${s}">`).join("\n ")}
|
|
1891
|
+
`;
|
|
1892
|
+
const searchParams = Object.fromEntries(url.searchParams.entries());
|
|
1893
|
+
let pageElement = React.createElement(PageComponent, { params: route.params, searchParams, query: searchParams });
|
|
1894
|
+
if (typeof PageComponent === "function") {
|
|
1895
|
+
try {
|
|
1896
|
+
const result = PageComponent({ params: route.params, searchParams, query: searchParams });
|
|
1897
|
+
if (result instanceof Promise) {
|
|
1898
|
+
pageElement = await result;
|
|
1899
|
+
}
|
|
1900
|
+
} catch (e) {
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
let layoutElement = React.createElement(LayoutComponent, { params: layoutParams, searchParams }, pageElement);
|
|
1904
|
+
if (typeof LayoutComponent === "function") {
|
|
1905
|
+
try {
|
|
1906
|
+
const result = LayoutComponent({ params: layoutParams, searchParams, children: pageElement });
|
|
1907
|
+
if (result instanceof Promise) {
|
|
1908
|
+
layoutElement = await result;
|
|
1909
|
+
}
|
|
1910
|
+
} catch (e) {
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
const ssrContent = renderToString(layoutElement);
|
|
1914
|
+
let finalHtml = await pluginManager.runWaterfallHook(PluginHooks.AFTER_RENDER, ssrContent, { route, config, isDev });
|
|
1915
|
+
const headInjectionsHtml = `
|
|
1916
|
+
${headInjections}
|
|
1917
|
+
`;
|
|
1918
|
+
const bodyInjectionsHtml = `
|
|
1919
|
+
<div id="__velix-islands"></div>
|
|
1920
|
+
${hydrationScript}${devToolsHtml}
|
|
1921
|
+
`;
|
|
1922
|
+
if (finalHtml.includes("<html")) {
|
|
1923
|
+
const headEnd = finalHtml.lastIndexOf("</head>");
|
|
1924
|
+
if (headEnd !== -1) {
|
|
1925
|
+
finalHtml = finalHtml.slice(0, headEnd) + headInjectionsHtml + finalHtml.slice(headEnd);
|
|
1926
|
+
} else {
|
|
1927
|
+
const bodyStart = finalHtml.search(/<body[^>]*>/i);
|
|
1928
|
+
if (bodyStart !== -1) {
|
|
1929
|
+
finalHtml = finalHtml.slice(0, bodyStart) + `<head>${headInjectionsHtml}</head>` + finalHtml.slice(bodyStart);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
const bodyEnd = finalHtml.lastIndexOf("</body>");
|
|
1933
|
+
if (bodyEnd !== -1) {
|
|
1934
|
+
finalHtml = finalHtml.slice(0, bodyEnd) + bodyInjectionsHtml + finalHtml.slice(bodyEnd);
|
|
1935
|
+
} else {
|
|
1936
|
+
finalHtml += bodyInjectionsHtml;
|
|
1937
|
+
}
|
|
1938
|
+
if (!finalHtml.trim().startsWith("<!DOCTYPE")) {
|
|
1939
|
+
finalHtml = "<!DOCTYPE html>\n" + finalHtml;
|
|
1940
|
+
}
|
|
1941
|
+
} else {
|
|
1942
|
+
finalHtml = `<!DOCTYPE html>
|
|
1943
|
+
<html lang="en">
|
|
1944
|
+
<head>
|
|
1945
|
+
${headInjectionsHtml}
|
|
1946
|
+
</head>
|
|
1947
|
+
<body>
|
|
1948
|
+
<div id="__velix">${ssrContent}</div>
|
|
1949
|
+
${bodyInjectionsHtml}
|
|
1950
|
+
</body>
|
|
1951
|
+
</html>`;
|
|
1952
|
+
}
|
|
1953
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
1954
|
+
res.end(finalHtml);
|
|
1955
|
+
} catch (err) {
|
|
1956
|
+
logger_default.error(`Render error: ${route.path}`, err);
|
|
1957
|
+
res.writeHead(500, { "Content-Type": "text/html; charset=utf-8" });
|
|
1958
|
+
res.end(generate500Page({
|
|
1959
|
+
title: "Render Error",
|
|
1960
|
+
message: err.message || "Failed to render page",
|
|
1961
|
+
stack: isDev ? err.stack : void 0,
|
|
1962
|
+
isDev,
|
|
1963
|
+
pathname: route.path
|
|
1964
|
+
}));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
async function serveVelixInternal(pathname, req, res, projectRoot) {
|
|
1968
|
+
if (pathname === "/__velix/hmr") {
|
|
1969
|
+
res.writeHead(200, {
|
|
1970
|
+
"Content-Type": "text/event-stream",
|
|
1971
|
+
"Cache-Control": "no-cache",
|
|
1972
|
+
"Connection": "keep-alive"
|
|
1973
|
+
});
|
|
1974
|
+
res.write("data: connected\n\n");
|
|
1975
|
+
const interval = setInterval(() => res.write(":heartbeat\n\n"), 3e4);
|
|
1976
|
+
if (res.req?.socket?.server?.__hmrClients) res.req.socket.server.__hmrClients.add(res);
|
|
1977
|
+
req.on("close", () => {
|
|
1978
|
+
clearInterval(interval);
|
|
1979
|
+
if (res.req?.socket?.server?.__hmrClients) res.req.socket.server.__hmrClients.delete(res);
|
|
1980
|
+
});
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
if (pathname === "/__velix/logo.webp") {
|
|
1984
|
+
const __filename2 = fileURLToPath(import.meta.url);
|
|
1985
|
+
const __dirname2 = path4.dirname(__filename2);
|
|
1986
|
+
const fallbackPath = path4.join(path4.dirname(pathToFileURL(__dirname2).pathname), "..", "assets", "logo.webp");
|
|
1987
|
+
const logoPath = fs4.existsSync(fallbackPath) ? fallbackPath : path4.join(process.cwd(), "node_modules", "velix", "assets", "logo.webp");
|
|
1988
|
+
if (fs4.existsSync(logoPath)) {
|
|
1989
|
+
res.writeHead(200, { "Content-Type": "image/webp", "Cache-Control": "public, max-age=31536000, immutable" });
|
|
1990
|
+
res.end(fs4.readFileSync(logoPath));
|
|
1991
|
+
} else {
|
|
1992
|
+
res.writeHead(404);
|
|
1993
|
+
res.end();
|
|
1994
|
+
}
|
|
1995
|
+
return;
|
|
1996
|
+
}
|
|
1997
|
+
if (pathname.startsWith("/__velix/islands/") && pathname.endsWith(".js")) {
|
|
1998
|
+
const componentName = pathname.replace("/__velix/islands/", "").replace(".js", "");
|
|
1999
|
+
try {
|
|
2000
|
+
const searchDirs = [
|
|
2001
|
+
path4.join(projectRoot, "components"),
|
|
2002
|
+
path4.join(projectRoot, "app"),
|
|
2003
|
+
path4.join(projectRoot, "islands")
|
|
2004
|
+
];
|
|
2005
|
+
let componentPath = "";
|
|
2006
|
+
for (const dir of searchDirs) {
|
|
2007
|
+
if (!fs4.existsSync(dir)) continue;
|
|
2008
|
+
const files = fs4.readdirSync(dir, { recursive: true });
|
|
2009
|
+
const found = files.find((f) => f.replace(/\\/g, "/").endsWith(`${componentName}.tsx`) || f.replace(/\\/g, "/").endsWith(`${componentName}.jsx`));
|
|
2010
|
+
if (found) {
|
|
2011
|
+
componentPath = path4.join(dir, found);
|
|
2012
|
+
break;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
if (!componentPath) {
|
|
2016
|
+
logger_default.error(`Island component not found: ${componentName}`);
|
|
2017
|
+
res.writeHead(404);
|
|
2018
|
+
res.end("Island component not found");
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
const result = await esbuild.build({
|
|
2022
|
+
entryPoints: [componentPath],
|
|
2023
|
+
bundle: true,
|
|
2024
|
+
format: "esm",
|
|
2025
|
+
platform: "browser",
|
|
2026
|
+
target: ["es2022"],
|
|
2027
|
+
minify: false,
|
|
2028
|
+
sourcemap: "inline",
|
|
2029
|
+
jsx: "automatic",
|
|
2030
|
+
external: ["react", "react-dom"],
|
|
2031
|
+
write: false
|
|
2032
|
+
});
|
|
2033
|
+
res.writeHead(200, { "Content-Type": "application/javascript" });
|
|
2034
|
+
res.end(result.outputFiles[0].text);
|
|
2035
|
+
return;
|
|
2036
|
+
} catch (err) {
|
|
2037
|
+
logger_default.error(`Island bundling failed: ${componentName}`, err);
|
|
2038
|
+
res.writeHead(500);
|
|
2039
|
+
res.end(`console.error("Island bundling failed: ${err.message}");`);
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
if (pathname === "/__velix/react.js" || pathname === "/__velix/react-dom-client.js") {
|
|
2044
|
+
const dep = pathname === "/__velix/react.js" ? "react" : "react-dom/client";
|
|
2045
|
+
try {
|
|
2046
|
+
const result = await esbuild.build({
|
|
2047
|
+
entryPoints: [dep],
|
|
2048
|
+
bundle: true,
|
|
2049
|
+
format: "esm",
|
|
2050
|
+
platform: "browser",
|
|
2051
|
+
target: ["es2022"],
|
|
2052
|
+
minify: true,
|
|
2053
|
+
write: false
|
|
2054
|
+
});
|
|
2055
|
+
res.writeHead(200, { "Content-Type": "application/javascript", "Cache-Control": "public, max-age=31536000, immutable" });
|
|
2056
|
+
res.end(result.outputFiles[0].text);
|
|
2057
|
+
return;
|
|
2058
|
+
} catch (err) {
|
|
2059
|
+
res.writeHead(500);
|
|
2060
|
+
res.end();
|
|
2061
|
+
return;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
res.writeHead(404);
|
|
2065
|
+
res.end("Not found");
|
|
2066
|
+
}
|
|
2067
|
+
function parseRequestBody(req) {
|
|
2068
|
+
return new Promise((resolve, reject) => {
|
|
2069
|
+
let body = "";
|
|
2070
|
+
req.on("data", (chunk) => {
|
|
2071
|
+
body += chunk;
|
|
2072
|
+
});
|
|
2073
|
+
req.on("end", () => {
|
|
2074
|
+
try {
|
|
2075
|
+
const ct = req.headers["content-type"] || "";
|
|
2076
|
+
if (ct.includes("application/json")) resolve(JSON.parse(body));
|
|
2077
|
+
else resolve(body);
|
|
2078
|
+
} catch {
|
|
2079
|
+
resolve(body);
|
|
2080
|
+
}
|
|
2081
|
+
});
|
|
2082
|
+
req.on("error", reject);
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
var server_default = { createServer, tailwindPlugin };
|
|
2086
|
+
|
|
2087
|
+
export { NotFoundError, PluginHooks, PluginManager, RedirectError, bindArgs, callServerAction, composeMiddleware, cookies, createServer, definePlugin, deserializeArgs, executeAction, formAction, generateJsonLd, generateMetadataTags, generateRobotsTxt, generateSitemap, getAction, getMethod, getPathname, headers, html, isMethod, json, jsonLd, loadMiddleware, loadPlugins, mergeMetadata, middlewares, notFound, parseFormData, parseJson, parseSearchParams, pluginManager, redirect, registerAction, runMiddleware, serverAction, server_default, tailwindPlugin, text, useActionContext, useVelixAction };
|
|
2088
|
+
//# sourceMappingURL=chunk-NVTZ6HRX.js.map
|
|
2089
|
+
//# sourceMappingURL=chunk-NVTZ6HRX.js.map
|