astro 2.3.4 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-base.d.ts +6 -0
- package/components/Code.astro +46 -21
- package/components/shiki-languages.js +172 -2016
- package/components/shiki-themes.js +41 -31
- package/dist/@types/app.d.js +0 -0
- package/dist/@types/astro.d.ts +108 -1
- package/dist/assets/internal.d.ts +6 -1
- package/dist/assets/internal.js +37 -4
- package/dist/content/runtime.js +8 -3
- package/dist/content/vite-plugin-content-assets.js +14 -4
- package/dist/core/app/index.js +50 -10
- package/dist/core/app/types.d.ts +10 -1
- package/dist/core/build/generate.js +62 -23
- package/dist/core/build/internal.d.ts +10 -4
- package/dist/core/build/internal.js +29 -18
- package/dist/core/build/page-data.js +2 -2
- package/dist/core/build/plugins/plugin-css.d.ts +1 -8
- package/dist/core/build/plugins/plugin-css.js +185 -150
- package/dist/core/build/plugins/plugin-pages.d.ts +1 -1
- package/dist/core/build/plugins/plugin-pages.js +13 -2
- package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
- package/dist/core/build/plugins/plugin-ssr.js +14 -5
- package/dist/core/build/types.d.ts +15 -6
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/config/config.js +5 -1
- package/dist/core/config/schema.d.ts +40 -0
- package/dist/core/config/schema.js +10 -2
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +3 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/dev/index.js +7 -4
- package/dist/core/endpoint/index.d.ts +9 -2
- package/dist/core/endpoint/index.js +42 -24
- package/dist/core/errors/errors-data.d.ts +81 -0
- package/dist/core/errors/errors-data.js +84 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +36 -0
- package/dist/core/middleware/callMiddleware.js +38 -0
- package/dist/core/middleware/index.d.ts +4 -0
- package/dist/core/middleware/index.js +8 -0
- package/dist/core/middleware/loadMiddleware.d.ts +8 -0
- package/dist/core/middleware/loadMiddleware.js +13 -0
- package/dist/core/middleware/sequence.d.ts +6 -0
- package/dist/core/middleware/sequence.js +27 -0
- package/dist/core/render/context.d.ts +7 -2
- package/dist/core/render/context.js +13 -2
- package/dist/core/render/core.d.ts +22 -2
- package/dist/core/render/core.js +68 -32
- package/dist/core/render/dev/index.d.ts +5 -1
- package/dist/core/render/dev/index.js +23 -3
- package/dist/core/render/index.d.ts +1 -1
- package/dist/core/render/index.js +7 -1
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +2 -1
- package/dist/core/render/ssr-element.d.ts +3 -2
- package/dist/core/render/ssr-element.js +22 -15
- package/dist/core/request.js +2 -0
- package/dist/integrations/index.js +1 -1
- package/dist/runtime/server/endpoint.js +1 -1
- package/dist/runtime/server/index.d.ts +1 -1
- package/dist/runtime/server/index.js +0 -2
- package/dist/runtime/server/render/head.js +3 -1
- package/dist/runtime/server/render/index.d.ts +1 -1
- package/dist/runtime/server/render/index.js +1 -2
- package/dist/runtime/server/render/tags.d.ts +2 -7
- package/dist/runtime/server/render/tags.js +9 -27
- package/dist/vite-plugin-astro-server/response.js +3 -3
- package/dist/vite-plugin-astro-server/route.js +7 -0
- package/package.json +10 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
2
|
+
async function callMiddleware(onRequest, apiContext, responseFunction) {
|
|
3
|
+
let resolveResolve;
|
|
4
|
+
new Promise((resolve) => {
|
|
5
|
+
resolveResolve = resolve;
|
|
6
|
+
});
|
|
7
|
+
let nextCalled = false;
|
|
8
|
+
const next = async () => {
|
|
9
|
+
nextCalled = true;
|
|
10
|
+
return await responseFunction();
|
|
11
|
+
};
|
|
12
|
+
let middlewarePromise = onRequest(apiContext, next);
|
|
13
|
+
return await Promise.resolve(middlewarePromise).then(async (value) => {
|
|
14
|
+
if (nextCalled) {
|
|
15
|
+
if (typeof value !== "undefined") {
|
|
16
|
+
if (value instanceof Response === false) {
|
|
17
|
+
throw new AstroError(AstroErrorData.MiddlewareNotAResponse);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
} else {
|
|
21
|
+
const responseResult = await responseFunction();
|
|
22
|
+
return responseResult;
|
|
23
|
+
}
|
|
24
|
+
} else if (typeof value === "undefined") {
|
|
25
|
+
throw new AstroError(AstroErrorData.MiddlewareNoDataOrNextCalled);
|
|
26
|
+
} else if (value instanceof Response === false) {
|
|
27
|
+
throw new AstroError(AstroErrorData.MiddlewareNotAResponse);
|
|
28
|
+
} else {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function isEndpointResult(response) {
|
|
34
|
+
return response && typeof response.body !== "undefined";
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
callMiddleware
|
|
38
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AstroSettings } from '../../@types/astro';
|
|
2
|
+
import type { ModuleLoader } from '../module-loader';
|
|
3
|
+
/**
|
|
4
|
+
* It accepts a module loader and the astro settings, and it attempts to load the middlewares defined in the configuration.
|
|
5
|
+
*
|
|
6
|
+
* If not middlewares were not set, the function returns an empty array.
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadMiddleware(moduleLoader: ModuleLoader, srcDir: AstroSettings['config']['srcDir']): Promise<Record<string, any> | undefined>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MIDDLEWARE_PATH_SEGMENT_NAME } from "../constants.js";
|
|
2
|
+
async function loadMiddleware(moduleLoader, srcDir) {
|
|
3
|
+
let middlewarePath = srcDir.pathname + "/" + MIDDLEWARE_PATH_SEGMENT_NAME;
|
|
4
|
+
try {
|
|
5
|
+
const module = await moduleLoader.import(middlewarePath);
|
|
6
|
+
return module;
|
|
7
|
+
} catch {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
loadMiddleware
|
|
13
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MiddlewareResponseHandler } from '../../@types/astro';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* It accepts one or more middleware handlers and makes sure that they are run in sequence.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sequence(...handlers: MiddlewareResponseHandler[]): MiddlewareResponseHandler;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineMiddleware } from "./index.js";
|
|
2
|
+
function sequence(...handlers) {
|
|
3
|
+
const length = handlers.length;
|
|
4
|
+
if (!length) {
|
|
5
|
+
const handler = defineMiddleware((context, next) => {
|
|
6
|
+
return next();
|
|
7
|
+
});
|
|
8
|
+
return handler;
|
|
9
|
+
}
|
|
10
|
+
return defineMiddleware((context, next) => {
|
|
11
|
+
return applyHandle(0, context);
|
|
12
|
+
function applyHandle(i, handleContext) {
|
|
13
|
+
const handle = handlers[i];
|
|
14
|
+
const result = handle(handleContext, async () => {
|
|
15
|
+
if (i < length - 1) {
|
|
16
|
+
return applyHandle(i + 1, handleContext);
|
|
17
|
+
} else {
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
sequence
|
|
27
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { RouteData, SSRElement, SSRResult } from '../../@types/astro';
|
|
1
|
+
import type { ComponentInstance, Params, Props, RouteData, SSRElement, SSRResult } from '../../@types/astro';
|
|
2
|
+
import type { Environment } from './environment';
|
|
2
3
|
/**
|
|
3
4
|
* The RenderContext represents the parts of rendering that are specific to one request.
|
|
4
5
|
*/
|
|
@@ -13,9 +14,13 @@ export interface RenderContext {
|
|
|
13
14
|
componentMetadata?: SSRResult['componentMetadata'];
|
|
14
15
|
route?: RouteData;
|
|
15
16
|
status?: number;
|
|
17
|
+
params: Params;
|
|
18
|
+
props: Props;
|
|
16
19
|
}
|
|
17
20
|
export type CreateRenderContextArgs = Partial<RenderContext> & {
|
|
18
21
|
origin?: string;
|
|
19
22
|
request: RenderContext['request'];
|
|
23
|
+
mod: ComponentInstance;
|
|
24
|
+
env: Environment;
|
|
20
25
|
};
|
|
21
|
-
export declare function createRenderContext(options: CreateRenderContextArgs): RenderContext
|
|
26
|
+
export declare function createRenderContext(options: CreateRenderContextArgs): Promise<RenderContext>;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { getParamsAndPropsOrThrow } from "./core.js";
|
|
2
|
+
async function createRenderContext(options) {
|
|
2
3
|
const request = options.request;
|
|
3
4
|
const url = new URL(request.url);
|
|
4
5
|
const origin = options.origin ?? url.origin;
|
|
5
6
|
const pathname = options.pathname ?? url.pathname;
|
|
7
|
+
const [params, props] = await getParamsAndPropsOrThrow({
|
|
8
|
+
mod: options.mod,
|
|
9
|
+
route: options.route,
|
|
10
|
+
routeCache: options.env.routeCache,
|
|
11
|
+
pathname,
|
|
12
|
+
logging: options.env.logging,
|
|
13
|
+
ssr: options.env.ssr
|
|
14
|
+
});
|
|
6
15
|
return {
|
|
7
16
|
...options,
|
|
8
17
|
origin,
|
|
9
18
|
pathname,
|
|
10
|
-
url
|
|
19
|
+
url,
|
|
20
|
+
params,
|
|
21
|
+
props
|
|
11
22
|
};
|
|
12
23
|
}
|
|
13
24
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentInstance, Params, Props, RouteData } from '../../@types/astro';
|
|
1
|
+
import type { APIContext, ComponentInstance, Params, Props, RouteData } from '../../@types/astro';
|
|
2
2
|
import type { LogOptions } from '../logger/core.js';
|
|
3
3
|
import type { RenderContext } from './context.js';
|
|
4
4
|
import type { Environment } from './environment.js';
|
|
@@ -14,6 +14,26 @@ interface GetParamsAndPropsOptions {
|
|
|
14
14
|
export declare const enum GetParamsAndPropsError {
|
|
15
15
|
NoMatchingStaticPath = 0
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* It retrieves `Params` and `Props`, or throws an error
|
|
19
|
+
* if they are not correctly retrieved.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getParamsAndPropsOrThrow(options: GetParamsAndPropsOptions): Promise<[Params, Props]>;
|
|
17
22
|
export declare function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise<[Params, Props] | GetParamsAndPropsError>;
|
|
18
|
-
export
|
|
23
|
+
export type RenderPage = {
|
|
24
|
+
mod: ComponentInstance;
|
|
25
|
+
renderContext: RenderContext;
|
|
26
|
+
env: Environment;
|
|
27
|
+
apiContext?: APIContext;
|
|
28
|
+
};
|
|
29
|
+
export declare function renderPage({ mod, renderContext, env, apiContext }: RenderPage): Promise<Response>;
|
|
30
|
+
/**
|
|
31
|
+
* Checks whether any value can is serializable.
|
|
32
|
+
*
|
|
33
|
+
* A serializable value contains plain values. For example, `Proxy`, `Set`, `Map`, functions, etc.
|
|
34
|
+
* are not serializable objects.
|
|
35
|
+
*
|
|
36
|
+
* @param object
|
|
37
|
+
*/
|
|
38
|
+
export declare function isValueSerializable(value: unknown): boolean;
|
|
19
39
|
export {};
|
package/dist/core/render/core.js
CHANGED
|
@@ -8,6 +8,18 @@ var GetParamsAndPropsError = /* @__PURE__ */ ((GetParamsAndPropsError2) => {
|
|
|
8
8
|
GetParamsAndPropsError2[GetParamsAndPropsError2["NoMatchingStaticPath"] = 0] = "NoMatchingStaticPath";
|
|
9
9
|
return GetParamsAndPropsError2;
|
|
10
10
|
})(GetParamsAndPropsError || {});
|
|
11
|
+
async function getParamsAndPropsOrThrow(options) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
let paramsAndPropsResp = await getParamsAndProps(options);
|
|
14
|
+
if (paramsAndPropsResp === 0 /* NoMatchingStaticPath */) {
|
|
15
|
+
throw new AstroError({
|
|
16
|
+
...AstroErrorData.NoMatchingStaticPathFound,
|
|
17
|
+
message: AstroErrorData.NoMatchingStaticPathFound.message(options.pathname),
|
|
18
|
+
hint: ((_a = options.route) == null ? void 0 : _a.component) ? AstroErrorData.NoMatchingStaticPathFound.hint([(_b = options.route) == null ? void 0 : _b.component]) : ""
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return paramsAndPropsResp;
|
|
22
|
+
}
|
|
11
23
|
async function getParamsAndProps(opts) {
|
|
12
24
|
const { logging, mod, route, routeCache, pathname, ssr } = opts;
|
|
13
25
|
let params = {};
|
|
@@ -49,65 +61,89 @@ async function getParamsAndProps(opts) {
|
|
|
49
61
|
}
|
|
50
62
|
return [params, pageProps];
|
|
51
63
|
}
|
|
52
|
-
async function renderPage(mod,
|
|
53
|
-
var _a, _b;
|
|
54
|
-
const paramsAndPropsRes = await getParamsAndProps({
|
|
55
|
-
logging: env.logging,
|
|
56
|
-
mod,
|
|
57
|
-
route: ctx.route,
|
|
58
|
-
routeCache: env.routeCache,
|
|
59
|
-
pathname: ctx.pathname,
|
|
60
|
-
ssr: env.ssr
|
|
61
|
-
});
|
|
62
|
-
if (paramsAndPropsRes === 0 /* NoMatchingStaticPath */) {
|
|
63
|
-
throw new AstroError({
|
|
64
|
-
...AstroErrorData.NoMatchingStaticPathFound,
|
|
65
|
-
message: AstroErrorData.NoMatchingStaticPathFound.message(ctx.pathname),
|
|
66
|
-
hint: ((_a = ctx.route) == null ? void 0 : _a.component) ? AstroErrorData.NoMatchingStaticPathFound.hint([(_b = ctx.route) == null ? void 0 : _b.component]) : ""
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
const [params, pageProps] = paramsAndPropsRes;
|
|
64
|
+
async function renderPage({ mod, renderContext, env, apiContext }) {
|
|
70
65
|
const Component = mod.default;
|
|
71
66
|
if (!Component)
|
|
72
67
|
throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
|
|
68
|
+
let locals = {};
|
|
69
|
+
if (apiContext) {
|
|
70
|
+
if (env.mode === "development" && !isValueSerializable(apiContext.locals)) {
|
|
71
|
+
throw new AstroError({
|
|
72
|
+
...AstroErrorData.LocalsNotSerializable,
|
|
73
|
+
message: AstroErrorData.LocalsNotSerializable.message(renderContext.pathname)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
locals = apiContext.locals;
|
|
77
|
+
}
|
|
73
78
|
const result = createResult({
|
|
74
79
|
adapterName: env.adapterName,
|
|
75
|
-
links:
|
|
76
|
-
styles:
|
|
80
|
+
links: renderContext.links,
|
|
81
|
+
styles: renderContext.styles,
|
|
77
82
|
logging: env.logging,
|
|
78
83
|
markdown: env.markdown,
|
|
79
84
|
mode: env.mode,
|
|
80
|
-
origin:
|
|
81
|
-
params,
|
|
82
|
-
props:
|
|
83
|
-
pathname:
|
|
84
|
-
componentMetadata:
|
|
85
|
+
origin: renderContext.origin,
|
|
86
|
+
params: renderContext.params,
|
|
87
|
+
props: renderContext.props,
|
|
88
|
+
pathname: renderContext.pathname,
|
|
89
|
+
componentMetadata: renderContext.componentMetadata,
|
|
85
90
|
resolve: env.resolve,
|
|
86
91
|
renderers: env.renderers,
|
|
87
|
-
request:
|
|
92
|
+
request: renderContext.request,
|
|
88
93
|
site: env.site,
|
|
89
|
-
scripts:
|
|
94
|
+
scripts: renderContext.scripts,
|
|
90
95
|
ssr: env.ssr,
|
|
91
|
-
status:
|
|
96
|
+
status: renderContext.status ?? 200,
|
|
97
|
+
locals
|
|
92
98
|
});
|
|
93
99
|
if (typeof mod.components === "object") {
|
|
94
|
-
Object.assign(
|
|
100
|
+
Object.assign(renderContext.props, { components: mod.components });
|
|
95
101
|
}
|
|
96
|
-
|
|
102
|
+
let response = await runtimeRenderPage(
|
|
97
103
|
result,
|
|
98
104
|
Component,
|
|
99
|
-
|
|
105
|
+
renderContext.props,
|
|
100
106
|
null,
|
|
101
107
|
env.streaming,
|
|
102
|
-
|
|
108
|
+
renderContext.route
|
|
103
109
|
);
|
|
104
110
|
if (result.cookies) {
|
|
105
111
|
attachToResponse(response, result.cookies);
|
|
106
112
|
}
|
|
107
113
|
return response;
|
|
108
114
|
}
|
|
115
|
+
function isValueSerializable(value) {
|
|
116
|
+
let type = typeof value;
|
|
117
|
+
let plainObject = true;
|
|
118
|
+
if (type === "object" && isPlainObject(value)) {
|
|
119
|
+
for (const [, nestedValue] of Object.entries(value)) {
|
|
120
|
+
if (!isValueSerializable(nestedValue)) {
|
|
121
|
+
plainObject = false;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
plainObject = false;
|
|
127
|
+
}
|
|
128
|
+
let result = value === null || type === "string" || type === "number" || type === "boolean" || Array.isArray(value) || plainObject;
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function isPlainObject(value) {
|
|
132
|
+
if (typeof value !== "object" || value === null)
|
|
133
|
+
return false;
|
|
134
|
+
let proto = Object.getPrototypeOf(value);
|
|
135
|
+
if (proto === null)
|
|
136
|
+
return true;
|
|
137
|
+
let baseProto = proto;
|
|
138
|
+
while (Object.getPrototypeOf(baseProto) !== null) {
|
|
139
|
+
baseProto = Object.getPrototypeOf(baseProto);
|
|
140
|
+
}
|
|
141
|
+
return proto === baseProto;
|
|
142
|
+
}
|
|
109
143
|
export {
|
|
110
144
|
GetParamsAndPropsError,
|
|
111
145
|
getParamsAndProps,
|
|
146
|
+
getParamsAndPropsOrThrow,
|
|
147
|
+
isValueSerializable,
|
|
112
148
|
renderPage
|
|
113
149
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AstroSettings, ComponentInstance, RouteData, SSRLoadedRenderer } from '../../../@types/astro';
|
|
1
|
+
import type { AstroMiddlewareInstance, AstroSettings, ComponentInstance, RouteData, SSRLoadedRenderer } from '../../../@types/astro';
|
|
2
2
|
import type { ModuleLoader } from '../../module-loader/index';
|
|
3
3
|
import type { DevelopmentEnvironment } from './environment';
|
|
4
4
|
export { createDevelopmentEnvironment } from './environment.js';
|
|
@@ -18,6 +18,10 @@ export interface SSROptions {
|
|
|
18
18
|
request: Request;
|
|
19
19
|
/** optional, in case we need to render something outside of a dev server */
|
|
20
20
|
route?: RouteData;
|
|
21
|
+
/**
|
|
22
|
+
* Optional middlewares
|
|
23
|
+
*/
|
|
24
|
+
middleware?: AstroMiddlewareInstance<unknown>;
|
|
21
25
|
}
|
|
22
26
|
export type ComponentPreload = [SSRLoadedRenderer[], ComponentInstance];
|
|
23
27
|
export declare function loadRenderers(moduleLoader: ModuleLoader, settings: AstroSettings): Promise<SSRLoadedRenderer[]>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { fileURLToPath } from "url";
|
|
2
2
|
import { PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
|
|
3
|
+
import { createAPIContext } from "../../endpoint/index.js";
|
|
3
4
|
import { enhanceViteSSRError } from "../../errors/dev/index.js";
|
|
4
5
|
import { AggregateError, CSSError, MarkdownError } from "../../errors/index.js";
|
|
6
|
+
import { callMiddleware } from "../../middleware/callMiddleware.js";
|
|
5
7
|
import { isPage, resolveIdToUrl, viteID } from "../../util.js";
|
|
6
8
|
import { createRenderContext, renderPage as coreRenderPage } from "../index.js";
|
|
7
9
|
import { filterFoundRenderers, loadRenderer } from "../renderer.js";
|
|
@@ -96,7 +98,8 @@ async function renderPage(options) {
|
|
|
96
98
|
env: options.env,
|
|
97
99
|
filePath: options.filePath
|
|
98
100
|
});
|
|
99
|
-
const
|
|
101
|
+
const { env } = options;
|
|
102
|
+
const renderContext = await createRenderContext({
|
|
100
103
|
request: options.request,
|
|
101
104
|
origin: options.origin,
|
|
102
105
|
pathname: options.pathname,
|
|
@@ -104,9 +107,26 @@ async function renderPage(options) {
|
|
|
104
107
|
links,
|
|
105
108
|
styles,
|
|
106
109
|
componentMetadata: metadata,
|
|
107
|
-
route: options.route
|
|
110
|
+
route: options.route,
|
|
111
|
+
mod,
|
|
112
|
+
env
|
|
108
113
|
});
|
|
109
|
-
|
|
114
|
+
if (options.middleware) {
|
|
115
|
+
if (options.middleware && options.middleware.onRequest) {
|
|
116
|
+
const apiContext = createAPIContext({
|
|
117
|
+
request: options.request,
|
|
118
|
+
params: renderContext.params,
|
|
119
|
+
props: renderContext.props,
|
|
120
|
+
adapterName: options.env.adapterName
|
|
121
|
+
});
|
|
122
|
+
const onRequest = options.middleware.onRequest;
|
|
123
|
+
const response = await callMiddleware(onRequest, apiContext, () => {
|
|
124
|
+
return coreRenderPage({ mod, renderContext, env: options.env, apiContext });
|
|
125
|
+
});
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return await coreRenderPage({ mod, renderContext, env: options.env });
|
|
110
130
|
}
|
|
111
131
|
export {
|
|
112
132
|
createDevelopmentEnvironment,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createRenderContext } from './context.js';
|
|
2
2
|
export type { RenderContext } from './context.js';
|
|
3
|
-
export { getParamsAndProps, GetParamsAndPropsError, renderPage } from './core.js';
|
|
3
|
+
export { getParamsAndProps, GetParamsAndPropsError, getParamsAndPropsOrThrow, renderPage, } from './core.js';
|
|
4
4
|
export type { Environment } from './environment';
|
|
5
5
|
export { createBasicEnvironment, createEnvironment } from './environment.js';
|
|
6
6
|
export { loadRenderer } from './renderer.js';
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { createRenderContext } from "./context.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getParamsAndProps,
|
|
4
|
+
GetParamsAndPropsError,
|
|
5
|
+
getParamsAndPropsOrThrow,
|
|
6
|
+
renderPage
|
|
7
|
+
} from "./core.js";
|
|
3
8
|
import { createBasicEnvironment, createEnvironment } from "./environment.js";
|
|
4
9
|
import { loadRenderer } from "./renderer.js";
|
|
5
10
|
export {
|
|
@@ -8,6 +13,7 @@ export {
|
|
|
8
13
|
createEnvironment,
|
|
9
14
|
createRenderContext,
|
|
10
15
|
getParamsAndProps,
|
|
16
|
+
getParamsAndPropsOrThrow,
|
|
11
17
|
loadRenderer,
|
|
12
18
|
renderPage
|
|
13
19
|
};
|
|
@@ -87,7 +87,7 @@ class Slots {
|
|
|
87
87
|
}
|
|
88
88
|
let renderMarkdown = null;
|
|
89
89
|
function createResult(args) {
|
|
90
|
-
const { markdown, params, pathname, renderers, request, resolve } = args;
|
|
90
|
+
const { markdown, params, pathname, renderers, request, resolve, locals } = args;
|
|
91
91
|
const url = new URL(request.url);
|
|
92
92
|
const headers = new Headers();
|
|
93
93
|
headers.set("Content-Type", "text/html");
|
|
@@ -141,6 +141,7 @@ function createResult(args) {
|
|
|
141
141
|
},
|
|
142
142
|
params,
|
|
143
143
|
props,
|
|
144
|
+
locals,
|
|
144
145
|
request,
|
|
145
146
|
url,
|
|
146
147
|
redirect: args.ssr ? (path, status) => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { SSRElement } from '../../@types/astro';
|
|
2
|
+
import type { StylesheetAsset } from '../app/types';
|
|
2
3
|
export declare function createAssetLink(href: string, base?: string, assetsPrefix?: string): string;
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function createStylesheetElement(stylesheet: StylesheetAsset, base?: string, assetsPrefix?: string): SSRElement;
|
|
5
|
+
export declare function createStylesheetElementSet(stylesheets: StylesheetAsset[], base?: string, assetsPrefix?: string): Set<SSRElement>;
|
|
5
6
|
export declare function createModuleScriptElement(script: {
|
|
6
7
|
type: 'inline' | 'external';
|
|
7
8
|
value: string;
|
|
@@ -9,19 +9,26 @@ function createAssetLink(href, base, assetsPrefix) {
|
|
|
9
9
|
return href;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
function createStylesheetElement(stylesheet, base, assetsPrefix) {
|
|
13
|
+
if (stylesheet.type === "inline") {
|
|
14
|
+
return {
|
|
15
|
+
props: {
|
|
16
|
+
type: "text/css"
|
|
17
|
+
},
|
|
18
|
+
children: stylesheet.content
|
|
19
|
+
};
|
|
20
|
+
} else {
|
|
21
|
+
return {
|
|
22
|
+
props: {
|
|
23
|
+
rel: "stylesheet",
|
|
24
|
+
href: createAssetLink(stylesheet.src, base, assetsPrefix)
|
|
25
|
+
},
|
|
26
|
+
children: ""
|
|
27
|
+
};
|
|
28
|
+
}
|
|
20
29
|
}
|
|
21
|
-
function
|
|
22
|
-
return new Set(
|
|
23
|
-
hrefs.map((href) => createLinkStylesheetElement(href, base, assetsPrefix))
|
|
24
|
-
);
|
|
30
|
+
function createStylesheetElementSet(stylesheets, base, assetsPrefix) {
|
|
31
|
+
return new Set(stylesheets.map((s) => createStylesheetElement(s, base, assetsPrefix)));
|
|
25
32
|
}
|
|
26
33
|
function createModuleScriptElement(script, base, assetsPrefix) {
|
|
27
34
|
if (script.type === "external") {
|
|
@@ -56,10 +63,10 @@ function createModuleScriptsSet(scripts, base, assetsPrefix) {
|
|
|
56
63
|
}
|
|
57
64
|
export {
|
|
58
65
|
createAssetLink,
|
|
59
|
-
createLinkStylesheetElement,
|
|
60
|
-
createLinkStylesheetElementSet,
|
|
61
66
|
createModuleScriptElement,
|
|
62
67
|
createModuleScriptElementWithSrc,
|
|
63
68
|
createModuleScriptElementWithSrcSet,
|
|
64
|
-
createModuleScriptsSet
|
|
69
|
+
createModuleScriptsSet,
|
|
70
|
+
createStylesheetElement,
|
|
71
|
+
createStylesheetElementSet
|
|
65
72
|
};
|
package/dist/core/request.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { warn } from "./logger/core.js";
|
|
2
2
|
const clientAddressSymbol = Symbol.for("astro.clientAddress");
|
|
3
|
+
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
3
4
|
function createRequest({
|
|
4
5
|
url,
|
|
5
6
|
headers,
|
|
@@ -40,6 +41,7 @@ function createRequest({
|
|
|
40
41
|
} else if (clientAddress) {
|
|
41
42
|
Reflect.set(request, clientAddressSymbol, clientAddress);
|
|
42
43
|
}
|
|
44
|
+
Reflect.set(request, clientLocalsSymbol, {});
|
|
43
45
|
return request;
|
|
44
46
|
}
|
|
45
47
|
export {
|
|
@@ -30,7 +30,7 @@ async function runHookConfigSetup({
|
|
|
30
30
|
let updatedConfig = { ...settings.config };
|
|
31
31
|
let updatedSettings = { ...settings, config: updatedConfig };
|
|
32
32
|
for (const integration of settings.config.integrations) {
|
|
33
|
-
if ((_a = integration
|
|
33
|
+
if ((_a = integration.hooks) == null ? void 0 : _a["astro:config:setup"]) {
|
|
34
34
|
let addPageExtension2 = function(...input) {
|
|
35
35
|
const exts = input.flat(Infinity).map((ext) => `.${ext.replace(/^\./, "")}`);
|
|
36
36
|
updatedSettings.pageExtensions.push(...exts);
|
|
@@ -12,7 +12,7 @@ function getHandlerFromModule(mod, method) {
|
|
|
12
12
|
}
|
|
13
13
|
async function renderEndpoint(mod, context, ssr) {
|
|
14
14
|
var _a;
|
|
15
|
-
const { request, params } = context;
|
|
15
|
+
const { request, params, locals } = context;
|
|
16
16
|
const chosenMethod = (_a = request.method) == null ? void 0 : _a.toLowerCase();
|
|
17
17
|
const handler = getHandlerFromModule(mod, chosenMethod);
|
|
18
18
|
if (!ssr && ssr === false && chosenMethod && chosenMethod !== "get") {
|
|
@@ -3,7 +3,7 @@ export { createAstro } from './astro-global.js';
|
|
|
3
3
|
export { renderEndpoint } from './endpoint.js';
|
|
4
4
|
export { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from './escape.js';
|
|
5
5
|
export { renderJSX } from './jsx.js';
|
|
6
|
-
export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderScriptElement, renderSlot, renderSlotToString,
|
|
6
|
+
export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderScriptElement, renderSlot, renderSlotToString, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, stringifyChunk, voidElementNames, } from './render/index.js';
|
|
7
7
|
export type { AstroComponentFactory, AstroComponentInstance, ComponentSlots, RenderInstruction, } from './render/index.js';
|
|
8
8
|
export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
|
|
9
9
|
/** @internal Associate JSX components with a specific renderer (see /src/vite-plugin-jsx/tag.ts) */
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
renderScriptElement,
|
|
20
20
|
renderSlot,
|
|
21
21
|
renderSlotToString,
|
|
22
|
-
renderStyleElement,
|
|
23
22
|
renderTemplate,
|
|
24
23
|
renderTemplate as renderTemplate2,
|
|
25
24
|
renderToString,
|
|
@@ -109,7 +108,6 @@ export {
|
|
|
109
108
|
renderScriptElement,
|
|
110
109
|
renderSlot,
|
|
111
110
|
renderSlotToString,
|
|
112
|
-
renderStyleElement,
|
|
113
111
|
renderTemplate2 as renderTemplate,
|
|
114
112
|
renderToString,
|
|
115
113
|
renderUniqueStylesheet,
|
|
@@ -7,7 +7,9 @@ const uniqueElements = (item, index, all) => {
|
|
|
7
7
|
};
|
|
8
8
|
function renderAllHeadContent(result) {
|
|
9
9
|
result._metadata.hasRenderedHead = true;
|
|
10
|
-
const styles = Array.from(result.styles).filter(uniqueElements).map(
|
|
10
|
+
const styles = Array.from(result.styles).filter(uniqueElements).map(
|
|
11
|
+
(style) => style.props.rel === "stylesheet" ? renderElement("link", style) : renderElement("style", style)
|
|
12
|
+
);
|
|
11
13
|
result.styles.clear();
|
|
12
14
|
const scripts = Array.from(result.scripts).filter(uniqueElements).map((script, i) => {
|
|
13
15
|
return renderElement("script", script, false);
|
|
@@ -6,6 +6,6 @@ export { renderHTMLElement } from './dom.js';
|
|
|
6
6
|
export { maybeRenderHead, renderHead } from './head.js';
|
|
7
7
|
export { renderPage } from './page.js';
|
|
8
8
|
export { renderSlot, renderSlotToString, type ComponentSlots } from './slot.js';
|
|
9
|
-
export { renderScriptElement,
|
|
9
|
+
export { renderScriptElement, renderUniqueStylesheet } from './tags.js';
|
|
10
10
|
export type { RenderInstruction } from './types';
|
|
11
11
|
export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
|
|
@@ -10,7 +10,7 @@ import { renderHTMLElement } from "./dom.js";
|
|
|
10
10
|
import { maybeRenderHead, renderHead } from "./head.js";
|
|
11
11
|
import { renderPage } from "./page.js";
|
|
12
12
|
import { renderSlot, renderSlotToString } from "./slot.js";
|
|
13
|
-
import { renderScriptElement,
|
|
13
|
+
import { renderScriptElement, renderUniqueStylesheet } from "./tags.js";
|
|
14
14
|
import { addAttribute, defineScriptVars, voidElementNames } from "./util.js";
|
|
15
15
|
export {
|
|
16
16
|
Fragment,
|
|
@@ -28,7 +28,6 @@ export {
|
|
|
28
28
|
renderScriptElement,
|
|
29
29
|
renderSlot,
|
|
30
30
|
renderSlotToString,
|
|
31
|
-
renderStyleElement,
|
|
32
31
|
renderTemplate,
|
|
33
32
|
renderToString,
|
|
34
33
|
renderUniqueStylesheet,
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { SSRElement, SSRResult } from '../../../@types/astro';
|
|
2
|
-
|
|
2
|
+
import type { StylesheetAsset } from '../../../core/app/types';
|
|
3
3
|
export declare function renderScriptElement({ props, children }: SSRElement): string;
|
|
4
|
-
export declare function
|
|
5
|
-
href: string;
|
|
6
|
-
}): string;
|
|
7
|
-
export declare function renderUniqueStylesheet(result: SSRResult, link: {
|
|
8
|
-
href: string;
|
|
9
|
-
}): string;
|
|
4
|
+
export declare function renderUniqueStylesheet(result: SSRResult, sheet: StylesheetAsset): string | undefined;
|