@ereo/core 0.2.35 → 0.2.37
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/app.d.ts +4 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/index.js +38 -3
- package/package.json +2 -2
package/dist/app.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export declare class EreoApp implements Application {
|
|
|
24
24
|
private pluginRegistry;
|
|
25
25
|
private middlewares;
|
|
26
26
|
private routeMatcher;
|
|
27
|
+
private static readonly METHOD_OVERRIDE_HEADER;
|
|
28
|
+
private static readonly METHOD_OVERRIDE_ALLOWED;
|
|
27
29
|
constructor(options?: ApplicationOptions);
|
|
28
30
|
/**
|
|
29
31
|
* Deep merge configuration objects.
|
|
@@ -62,6 +64,8 @@ export declare class EreoApp implements Application {
|
|
|
62
64
|
* Handle a route request.
|
|
63
65
|
*/
|
|
64
66
|
private handleRoute;
|
|
67
|
+
private normalizeBasePath;
|
|
68
|
+
private getEffectiveMethod;
|
|
65
69
|
/**
|
|
66
70
|
* Safely serialize data as a JSON response.
|
|
67
71
|
*/
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,MAAM,EACN,KAAK,EACL,UAAU,EACV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAsB1C;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAEnE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAErE;AAED;;GAEG;AACH,qBAAa,OAAQ,YAAW,WAAW;IACzC,QAAQ,CAAC,MAAM,EAAE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,KAAK,UAAU,GAAG,IAAI,GAAG,IAAI;IAIvE;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI;IAIhC;;OAEG;YACW,iBAAiB;IAU/B;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgBjD;;OAEG;YACW,aAAa;IAkB3B;;OAEG;YACW,WAAW;IAsFzB,OAAO,CAAC,iBAAiB;YAOX,kBAAkB;IA8BhC;;OAEG;IACH,OAAO,CAAC,YAAY;IAiBpB;;OAEG;IACH,OAAO,CAAC,WAAW;IAsBnB;;;OAGG;IACG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAS1B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;OAEG;IACH,iBAAiB,IAAI,cAAc;CAGpC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAE1D"}
|
package/dist/index.js
CHANGED
|
@@ -373,6 +373,8 @@ class EreoApp {
|
|
|
373
373
|
pluginRegistry;
|
|
374
374
|
middlewares = [];
|
|
375
375
|
routeMatcher = null;
|
|
376
|
+
static METHOD_OVERRIDE_HEADER = "_method";
|
|
377
|
+
static METHOD_OVERRIDE_ALLOWED = new Set(["PUT", "PATCH", "DELETE"]);
|
|
376
378
|
constructor(options = {}) {
|
|
377
379
|
this.config = this.mergeConfig(defaultConfig, options.config || {});
|
|
378
380
|
const mode = this.config.server?.development ? "development" : "production";
|
|
@@ -435,8 +437,13 @@ class EreoApp {
|
|
|
435
437
|
async handleRoute(request, context) {
|
|
436
438
|
const url = new URL(request.url);
|
|
437
439
|
let pathname = url.pathname;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
+
const effectiveMethod = await this.getEffectiveMethod(request);
|
|
441
|
+
const normalizedBasePath = this.normalizeBasePath(this.config.basePath);
|
|
442
|
+
if (normalizedBasePath && (pathname === normalizedBasePath || pathname.startsWith(normalizedBasePath + "/"))) {
|
|
443
|
+
pathname = pathname.slice(normalizedBasePath.length) || "/";
|
|
444
|
+
if (!pathname.startsWith("/")) {
|
|
445
|
+
pathname = "/" + pathname;
|
|
446
|
+
}
|
|
440
447
|
}
|
|
441
448
|
if (!this.routeMatcher) {
|
|
442
449
|
return new Response("Router not configured", { status: 500 });
|
|
@@ -449,7 +456,7 @@ class EreoApp {
|
|
|
449
456
|
return new Response("Route module not loaded", { status: 500 });
|
|
450
457
|
}
|
|
451
458
|
const module = match.route.module;
|
|
452
|
-
if (
|
|
459
|
+
if (effectiveMethod !== "GET" && effectiveMethod !== "HEAD") {
|
|
453
460
|
if (module.action) {
|
|
454
461
|
const actionData = await module.action({
|
|
455
462
|
request,
|
|
@@ -480,6 +487,34 @@ class EreoApp {
|
|
|
480
487
|
}
|
|
481
488
|
return this.jsonResponse({ loaderData, params: match.params });
|
|
482
489
|
}
|
|
490
|
+
normalizeBasePath(basePath) {
|
|
491
|
+
if (!basePath || basePath === "/") {
|
|
492
|
+
return "";
|
|
493
|
+
}
|
|
494
|
+
return basePath.replace(/\/+$/, "");
|
|
495
|
+
}
|
|
496
|
+
async getEffectiveMethod(request) {
|
|
497
|
+
const method = request.method.toUpperCase();
|
|
498
|
+
if (method !== "POST") {
|
|
499
|
+
return method;
|
|
500
|
+
}
|
|
501
|
+
const contentType = request.headers.get("Content-Type") || "";
|
|
502
|
+
const isFormSubmission = contentType.includes("application/x-www-form-urlencoded") || contentType.includes("multipart/form-data");
|
|
503
|
+
if (!isFormSubmission) {
|
|
504
|
+
return method;
|
|
505
|
+
}
|
|
506
|
+
try {
|
|
507
|
+
const formData = await request.clone().formData();
|
|
508
|
+
const override = formData.get(EreoApp.METHOD_OVERRIDE_HEADER);
|
|
509
|
+
if (typeof override !== "string") {
|
|
510
|
+
return method;
|
|
511
|
+
}
|
|
512
|
+
const normalized = override.toUpperCase();
|
|
513
|
+
return EreoApp.METHOD_OVERRIDE_ALLOWED.has(normalized) ? normalized : method;
|
|
514
|
+
} catch {
|
|
515
|
+
return method;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
483
518
|
jsonResponse(data, status = 200) {
|
|
484
519
|
try {
|
|
485
520
|
return new Response(JSON.stringify(data), {
|
package/package.json
CHANGED