astro 4.16.1 → 4.16.2
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/actions/runtime/middleware.js +2 -8
- package/dist/content/content-layer.js +3 -3
- package/dist/core/constants.d.ts +0 -4
- package/dist/core/constants.js +1 -3
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/sequence.js +2 -3
- package/dist/core/render-context.js +30 -5
- package/dist/core/routing/rewrite.d.ts +0 -9
- package/dist/core/routing/rewrite.js +1 -38
- package/package.json +1 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { yellow } from "kleur/colors";
|
|
2
|
-
import { ASTRO_ORIGIN_HEADER } from "../../core/constants.js";
|
|
3
2
|
import { defineMiddleware } from "../../core/middleware/index.js";
|
|
4
|
-
import { getOriginHeader } from "../../core/routing/rewrite.js";
|
|
5
3
|
import { ACTION_QUERY_PARAMS } from "../consts.js";
|
|
6
4
|
import { formContentTypes, hasContentType } from "./utils.js";
|
|
7
5
|
import { getAction } from "./virtual/get-action.js";
|
|
@@ -86,14 +84,10 @@ async function redirectWithResult({
|
|
|
86
84
|
actionResult: serializeActionResult(actionResult)
|
|
87
85
|
});
|
|
88
86
|
if (actionResult.error) {
|
|
89
|
-
const
|
|
90
|
-
if (!
|
|
87
|
+
const referer = context.request.headers.get("Referer");
|
|
88
|
+
if (!referer) {
|
|
91
89
|
throw new Error("Internal: Referer unexpectedly missing from Action POST request.");
|
|
92
90
|
}
|
|
93
|
-
return context.redirect(referer2);
|
|
94
|
-
}
|
|
95
|
-
const referer = getOriginHeader(context.request);
|
|
96
|
-
if (referer) {
|
|
97
91
|
return context.redirect(referer);
|
|
98
92
|
}
|
|
99
93
|
return context.redirect(context.url.pathname);
|
|
@@ -121,7 +121,7 @@ class ContentLayer {
|
|
|
121
121
|
logger.info("Content config changed");
|
|
122
122
|
shouldClear = true;
|
|
123
123
|
}
|
|
124
|
-
if (previousAstroVersion !== "4.16.
|
|
124
|
+
if (previousAstroVersion !== "4.16.2") {
|
|
125
125
|
logger.info("Astro version changed");
|
|
126
126
|
shouldClear = true;
|
|
127
127
|
}
|
|
@@ -129,8 +129,8 @@ class ContentLayer {
|
|
|
129
129
|
logger.info("Clearing content store");
|
|
130
130
|
this.#store.clearAll();
|
|
131
131
|
}
|
|
132
|
-
if ("4.16.
|
|
133
|
-
await this.#store.metaStore().set("astro-version", "4.16.
|
|
132
|
+
if ("4.16.2") {
|
|
133
|
+
await this.#store.metaStore().set("astro-version", "4.16.2");
|
|
134
134
|
}
|
|
135
135
|
if (currentConfigDigest) {
|
|
136
136
|
await this.#store.metaStore().set("config-digest", currentConfigDigest);
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -25,10 +25,6 @@ export declare const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
|
|
|
25
25
|
* This metadata is used to determine the origin of a Response. If a rewrite has occurred, it should be prioritised over other logic.
|
|
26
26
|
*/
|
|
27
27
|
export declare const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
|
|
28
|
-
/**
|
|
29
|
-
* Header used to track the original URL requested by the user. This information is useful rewrites are involved.
|
|
30
|
-
*/
|
|
31
|
-
export declare const ASTRO_ORIGIN_HEADER = "X-Astro-Origin";
|
|
32
28
|
export declare const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
|
|
33
29
|
/**
|
|
34
30
|
* The name for the header used to help i18n middleware, which only needs to act on "page" and "fallback" route types.
|
package/dist/core/constants.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const ASTRO_VERSION = "4.16.
|
|
1
|
+
const ASTRO_VERSION = "4.16.2";
|
|
2
2
|
const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
|
|
3
3
|
const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
|
|
4
|
-
const ASTRO_ORIGIN_HEADER = "X-Astro-Origin";
|
|
5
4
|
const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
|
|
6
5
|
const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
|
|
7
6
|
const DEFAULT_404_COMPONENT = "astro-default-404.astro";
|
|
@@ -21,7 +20,6 @@ const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
|
|
|
21
20
|
];
|
|
22
21
|
const MIDDLEWARE_PATH_SEGMENT_NAME = "middleware";
|
|
23
22
|
export {
|
|
24
|
-
ASTRO_ORIGIN_HEADER,
|
|
25
23
|
ASTRO_VERSION,
|
|
26
24
|
DEFAULT_404_COMPONENT,
|
|
27
25
|
DEFAULT_500_COMPONENT,
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
|
|
|
22
22
|
await telemetry.record([]);
|
|
23
23
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
24
24
|
const logger = restart.container.logger;
|
|
25
|
-
const currentVersion = "4.16.
|
|
25
|
+
const currentVersion = "4.16.2";
|
|
26
26
|
const isPrerelease = currentVersion.includes("-");
|
|
27
27
|
if (!isPrerelease) {
|
|
28
28
|
try {
|
package/dist/core/messages.js
CHANGED
|
@@ -38,7 +38,7 @@ function serverStart({
|
|
|
38
38
|
host,
|
|
39
39
|
base
|
|
40
40
|
}) {
|
|
41
|
-
const version = "4.16.
|
|
41
|
+
const version = "4.16.2";
|
|
42
42
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
43
43
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
44
44
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -270,7 +270,7 @@ function printHelp({
|
|
|
270
270
|
message.push(
|
|
271
271
|
linebreak(),
|
|
272
272
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
273
|
-
`v${"4.16.
|
|
273
|
+
`v${"4.16.2"}`
|
|
274
274
|
)} ${headline}`
|
|
275
275
|
);
|
|
276
276
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AstroCookies } from "../cookies/cookies.js";
|
|
2
2
|
import { apiContextRoutesSymbol } from "../render-context.js";
|
|
3
3
|
import { getParams } from "../render/index.js";
|
|
4
|
-
import { copyRequest } from "../routing/rewrite.js";
|
|
5
4
|
import { defineMiddleware } from "./index.js";
|
|
6
5
|
function sequence(...handlers) {
|
|
7
6
|
const filtered = handlers.filter((h) => !!h);
|
|
@@ -23,9 +22,9 @@ function sequence(...handlers) {
|
|
|
23
22
|
if (payload instanceof Request) {
|
|
24
23
|
newRequest = payload;
|
|
25
24
|
} else if (payload instanceof URL) {
|
|
26
|
-
newRequest =
|
|
25
|
+
newRequest = new Request(payload, handleContext.request);
|
|
27
26
|
} else {
|
|
28
|
-
newRequest =
|
|
27
|
+
newRequest = new Request(
|
|
29
28
|
new URL(payload, handleContext.url.origin),
|
|
30
29
|
handleContext.request
|
|
31
30
|
);
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
import { renderEndpoint } from "../runtime/server/endpoint.js";
|
|
9
9
|
import { renderPage } from "../runtime/server/index.js";
|
|
10
10
|
import {
|
|
11
|
-
ASTRO_ORIGIN_HEADER,
|
|
12
11
|
ASTRO_VERSION,
|
|
13
12
|
REROUTE_DIRECTIVE_HEADER,
|
|
14
13
|
REWRITE_DIRECTIVE_HEADER_KEY,
|
|
@@ -25,7 +24,6 @@ import { callMiddleware } from "./middleware/callMiddleware.js";
|
|
|
25
24
|
import { sequence } from "./middleware/index.js";
|
|
26
25
|
import { renderRedirect } from "./redirects/render.js";
|
|
27
26
|
import { Slots, getParams, getProps } from "./render/index.js";
|
|
28
|
-
import { copyRequest, setOriginHeader } from "./routing/rewrite.js";
|
|
29
27
|
const apiContextRoutesSymbol = Symbol.for("context.routes");
|
|
30
28
|
class RenderContext {
|
|
31
29
|
constructor(pipeline, locals, middleware, pathname, request, routeData, status, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = new URL(request.url), props = {}) {
|
|
@@ -60,7 +58,6 @@ class RenderContext {
|
|
|
60
58
|
props
|
|
61
59
|
}) {
|
|
62
60
|
const pipelineMiddleware = await pipeline.getMiddleware();
|
|
63
|
-
setOriginHeader(request, pathname);
|
|
64
61
|
return new RenderContext(
|
|
65
62
|
pipeline,
|
|
66
63
|
locals,
|
|
@@ -121,7 +118,7 @@ class RenderContext {
|
|
|
121
118
|
if (payload instanceof Request) {
|
|
122
119
|
this.request = payload;
|
|
123
120
|
} else {
|
|
124
|
-
this.request = copyRequest(newUrl, this.request);
|
|
121
|
+
this.request = this.#copyRequest(newUrl, this.request);
|
|
125
122
|
}
|
|
126
123
|
this.isRewriting = true;
|
|
127
124
|
this.url = new URL(this.request.url);
|
|
@@ -205,7 +202,7 @@ class RenderContext {
|
|
|
205
202
|
if (reroutePayload instanceof Request) {
|
|
206
203
|
this.request = reroutePayload;
|
|
207
204
|
} else {
|
|
208
|
-
this.request = copyRequest(newUrl, this.request);
|
|
205
|
+
this.request = this.#copyRequest(newUrl, this.request);
|
|
209
206
|
}
|
|
210
207
|
this.url = new URL(this.request.url);
|
|
211
208
|
this.cookies = new AstroCookies(this.request);
|
|
@@ -451,6 +448,34 @@ class RenderContext {
|
|
|
451
448
|
if (!i18n) return;
|
|
452
449
|
return this.#preferredLocaleList ??= computePreferredLocaleList(request, i18n.locales);
|
|
453
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* Utility function that creates a new `Request` with a new URL from an old `Request`.
|
|
453
|
+
*
|
|
454
|
+
* @param newUrl The new `URL`
|
|
455
|
+
* @param oldRequest The old `Request`
|
|
456
|
+
*/
|
|
457
|
+
#copyRequest(newUrl, oldRequest) {
|
|
458
|
+
if (oldRequest.bodyUsed) {
|
|
459
|
+
throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
|
|
460
|
+
}
|
|
461
|
+
return new Request(newUrl, {
|
|
462
|
+
method: oldRequest.method,
|
|
463
|
+
headers: oldRequest.headers,
|
|
464
|
+
body: oldRequest.body,
|
|
465
|
+
referrer: oldRequest.referrer,
|
|
466
|
+
referrerPolicy: oldRequest.referrerPolicy,
|
|
467
|
+
mode: oldRequest.mode,
|
|
468
|
+
credentials: oldRequest.credentials,
|
|
469
|
+
cache: oldRequest.cache,
|
|
470
|
+
redirect: oldRequest.redirect,
|
|
471
|
+
integrity: oldRequest.integrity,
|
|
472
|
+
signal: oldRequest.signal,
|
|
473
|
+
keepalive: oldRequest.keepalive,
|
|
474
|
+
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
|
475
|
+
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
|
|
476
|
+
duplex: "half"
|
|
477
|
+
});
|
|
478
|
+
}
|
|
454
479
|
}
|
|
455
480
|
export {
|
|
456
481
|
RenderContext,
|
|
@@ -18,12 +18,3 @@ export interface FindRouteToRewriteResult {
|
|
|
18
18
|
* 2.
|
|
19
19
|
*/
|
|
20
20
|
export declare function findRouteToRewrite({ payload, routes, request, trailingSlash, buildFormat, base, }: FindRouteToRewrite): FindRouteToRewriteResult;
|
|
21
|
-
/**
|
|
22
|
-
* Utility function that creates a new `Request` with a new URL from an old `Request`.
|
|
23
|
-
*
|
|
24
|
-
* @param newUrl The new `URL`
|
|
25
|
-
* @param oldRequest The old `Request`
|
|
26
|
-
*/
|
|
27
|
-
export declare function copyRequest(newUrl: URL, oldRequest: Request): Request;
|
|
28
|
-
export declare function setOriginHeader(request: Request, pathname: string): void;
|
|
29
|
-
export declare function getOriginHeader(request: Request): string | undefined;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { shouldAppendForwardSlash } from "../build/util.js";
|
|
2
|
-
import { ASTRO_ORIGIN_HEADER } from "../constants.js";
|
|
3
|
-
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
4
2
|
import { appendForwardSlash, removeTrailingForwardSlash } from "../path.js";
|
|
5
3
|
import { DEFAULT_404_ROUTE } from "./astro-designed-error-pages.js";
|
|
6
4
|
function findRouteToRewrite({
|
|
@@ -46,41 +44,6 @@ function findRouteToRewrite({
|
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
|
-
function copyRequest(newUrl, oldRequest) {
|
|
50
|
-
if (oldRequest.bodyUsed) {
|
|
51
|
-
throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
|
|
52
|
-
}
|
|
53
|
-
return new Request(newUrl, {
|
|
54
|
-
method: oldRequest.method,
|
|
55
|
-
headers: oldRequest.headers,
|
|
56
|
-
body: oldRequest.body,
|
|
57
|
-
referrer: oldRequest.referrer,
|
|
58
|
-
referrerPolicy: oldRequest.referrerPolicy,
|
|
59
|
-
mode: oldRequest.mode,
|
|
60
|
-
credentials: oldRequest.credentials,
|
|
61
|
-
cache: oldRequest.cache,
|
|
62
|
-
redirect: oldRequest.redirect,
|
|
63
|
-
integrity: oldRequest.integrity,
|
|
64
|
-
signal: oldRequest.signal,
|
|
65
|
-
keepalive: oldRequest.keepalive,
|
|
66
|
-
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
|
67
|
-
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
|
|
68
|
-
duplex: "half"
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function setOriginHeader(request, pathname) {
|
|
72
|
-
request.headers.set(ASTRO_ORIGIN_HEADER, encodeURIComponent(pathname));
|
|
73
|
-
}
|
|
74
|
-
function getOriginHeader(request) {
|
|
75
|
-
const origin = request.headers.get(ASTRO_ORIGIN_HEADER);
|
|
76
|
-
if (origin) {
|
|
77
|
-
return decodeURIComponent(origin);
|
|
78
|
-
}
|
|
79
|
-
return void 0;
|
|
80
|
-
}
|
|
81
47
|
export {
|
|
82
|
-
|
|
83
|
-
findRouteToRewrite,
|
|
84
|
-
getOriginHeader,
|
|
85
|
-
setOriginHeader
|
|
48
|
+
findRouteToRewrite
|
|
86
49
|
};
|