@teamvelix/velix 5.1.5 → 5.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/build/index.js +2 -2
- package/dist/{chunk-TGNK4MY5.js → chunk-CFDPNOWM.js} +38 -26
- package/dist/chunk-CFDPNOWM.js.map +1 -0
- package/dist/{chunk-BXDKUP2L.js → chunk-SB5DCDTH.js} +3 -3
- package/dist/{chunk-BXDKUP2L.js.map → chunk-SB5DCDTH.js.map} +1 -1
- package/dist/{chunk-RFWV4CDG.js → chunk-X2EZAAQS.js} +3 -3
- package/dist/{chunk-RFWV4CDG.js.map → chunk-X2EZAAQS.js.map} +1 -1
- package/dist/index.d.ts +61 -60
- package/dist/index.js +3 -3
- package/dist/runtime/start-build.js +1 -1
- package/dist/runtime/start-build.js.map +1 -1
- package/dist/runtime/start-dev.js +38 -26
- package/dist/runtime/start-dev.js.map +1 -1
- package/dist/runtime/start-prod.js +38 -26
- package/dist/runtime/start-prod.js.map +1 -1
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-TGNK4MY5.js.map +0 -1
|
@@ -8,11 +8,11 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@
|
|
11
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postc_36112cdf9ab6125b194fc7941daee874/node_modules/tsup/assets/esm_shims.js
|
|
12
12
|
import path from "path";
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
14
|
var init_esm_shims = __esm({
|
|
15
|
-
"../../node_modules/.pnpm/tsup@8.5.1_jiti@
|
|
15
|
+
"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postc_36112cdf9ab6125b194fc7941daee874/node_modules/tsup/assets/esm_shims.js"() {
|
|
16
16
|
"use strict";
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -453,20 +453,22 @@ init_esm_shims();
|
|
|
453
453
|
import fs4 from "fs";
|
|
454
454
|
import path4 from "path";
|
|
455
455
|
async function loadMiddleware(projectRoot) {
|
|
456
|
-
const middlewareDir = path4.join(projectRoot, "middleware");
|
|
457
456
|
const fns = [];
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
|
|
457
|
+
const possibleFiles = ["proxy.ts", "proxy.js"];
|
|
458
|
+
for (const file of possibleFiles) {
|
|
459
|
+
const filePath = path4.join(projectRoot, file);
|
|
460
|
+
if (!fs4.existsSync(filePath)) continue;
|
|
461
461
|
try {
|
|
462
|
-
const filePath = path4.join(middlewareDir, file);
|
|
463
462
|
const { pathToFileURL: pathToFileURL4 } = await import("url");
|
|
464
463
|
const url = pathToFileURL4(filePath).href;
|
|
465
464
|
const mod = await import(`${url}?t=${Date.now()}`);
|
|
466
|
-
const fn = mod.default || mod.middleware;
|
|
467
|
-
if (typeof fn === "function")
|
|
465
|
+
const fn = mod.default || mod.proxy || mod.middleware;
|
|
466
|
+
if (typeof fn === "function") {
|
|
467
|
+
fns.push(fn);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
468
470
|
} catch (err) {
|
|
469
|
-
console.warn(`\u26A0 Failed to load
|
|
471
|
+
console.warn(`\u26A0 Failed to load proxy ${file}: ${err.message}`);
|
|
470
472
|
}
|
|
471
473
|
}
|
|
472
474
|
return fns;
|
|
@@ -691,7 +693,7 @@ init_esm_shims();
|
|
|
691
693
|
|
|
692
694
|
// version.ts
|
|
693
695
|
init_esm_shims();
|
|
694
|
-
var VERSION = "5.1.
|
|
696
|
+
var VERSION = "5.1.6";
|
|
695
697
|
|
|
696
698
|
// logger.ts
|
|
697
699
|
var colors = {
|
|
@@ -2360,26 +2362,26 @@ async function handleApiRoute(route, req, res, url) {
|
|
|
2360
2362
|
res.end(JSON.stringify({ error: "Method not allowed" }));
|
|
2361
2363
|
return;
|
|
2362
2364
|
}
|
|
2363
|
-
let
|
|
2365
|
+
let rawBody;
|
|
2364
2366
|
if (["POST", "PUT", "PATCH"].includes(method)) {
|
|
2365
|
-
|
|
2367
|
+
rawBody = await parseRawBody(req);
|
|
2366
2368
|
}
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
const response = await handler(request);
|
|
2369
|
+
const headers2 = new Headers();
|
|
2370
|
+
for (const [key, val] of Object.entries(req.headers)) {
|
|
2371
|
+
if (Array.isArray(val)) val.forEach((v) => headers2.append(key, v));
|
|
2372
|
+
else if (val) headers2.set(key, val);
|
|
2373
|
+
}
|
|
2374
|
+
const reqInit = { method, headers: headers2 };
|
|
2375
|
+
if (rawBody !== void 0) reqInit.body = rawBody;
|
|
2376
|
+
const request = new Request(url.href, reqInit);
|
|
2377
|
+
request.velixUrl = url;
|
|
2378
|
+
const response = await handler(request, { params: route.params || {} });
|
|
2377
2379
|
if (response instanceof Response) {
|
|
2378
|
-
const
|
|
2380
|
+
const headers3 = {};
|
|
2379
2381
|
response.headers.forEach((v, k) => {
|
|
2380
|
-
|
|
2382
|
+
headers3[k] = v;
|
|
2381
2383
|
});
|
|
2382
|
-
res.writeHead(response.status,
|
|
2384
|
+
res.writeHead(response.status, headers3);
|
|
2383
2385
|
const text = await response.text();
|
|
2384
2386
|
res.end(text);
|
|
2385
2387
|
} else if (typeof response === "object") {
|
|
@@ -2648,6 +2650,16 @@ function parseRequestBody(req) {
|
|
|
2648
2650
|
req.on("error", reject);
|
|
2649
2651
|
});
|
|
2650
2652
|
}
|
|
2653
|
+
function parseRawBody(req) {
|
|
2654
|
+
return new Promise((resolve, reject) => {
|
|
2655
|
+
let body = "";
|
|
2656
|
+
req.on("data", (chunk) => {
|
|
2657
|
+
body += chunk;
|
|
2658
|
+
});
|
|
2659
|
+
req.on("end", () => resolve(body));
|
|
2660
|
+
req.on("error", reject);
|
|
2661
|
+
});
|
|
2662
|
+
}
|
|
2651
2663
|
|
|
2652
2664
|
// runtime/start-prod.ts
|
|
2653
2665
|
async function startProd() {
|