Home / Function/ createActionAPIContext() — astro Function Reference

createActionAPIContext() — astro Function Reference

Architecture documentation for the createActionAPIContext() function in render-context.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  d91ba7de_e6ec_e3f2_d698_49f283edc9ab["createActionAPIContext()"]
  b7425a46_8c1f_1122_7ae3_a00e52db1d90["RenderContext"]
  d91ba7de_e6ec_e3f2_d698_49f283edc9ab -->|defined in| b7425a46_8c1f_1122_7ae3_a00e52db1d90
  9c5f11d9_36cd_d739_b7da_42358d602de6["render()"]
  9c5f11d9_36cd_d739_b7da_42358d602de6 -->|calls| d91ba7de_e6ec_e3f2_d698_49f283edc9ab
  8738ff41_9cb5_f0e0_abb2_ec740b39d0ad["getClientAddress()"]
  d91ba7de_e6ec_e3f2_d698_49f283edc9ab -->|calls| 8738ff41_9cb5_f0e0_abb2_ec740b39d0ad
  a1e64bf7_a3cd_6346_6068_fe2858acbe2e["computeCurrentLocale()"]
  d91ba7de_e6ec_e3f2_d698_49f283edc9ab -->|calls| a1e64bf7_a3cd_6346_6068_fe2858acbe2e
  259723fe_8d99_f1f3_d6ad_afa57fadf1b8["computePreferredLocale()"]
  d91ba7de_e6ec_e3f2_d698_49f283edc9ab -->|calls| 259723fe_8d99_f1f3_d6ad_afa57fadf1b8
  5c3edeac_afc1_52c5_f90c_50d258bfdbfd["computePreferredLocaleList()"]
  d91ba7de_e6ec_e3f2_d698_49f283edc9ab -->|calls| 5c3edeac_afc1_52c5_f90c_50d258bfdbfd
  style d91ba7de_e6ec_e3f2_d698_49f283edc9ab fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/render-context.ts lines 428–516

	createActionAPIContext(): ActionAPIContext {
		const renderContext = this;
		const { params, pipeline, url } = this;

		return {
			// Don't allow reassignment of cookies because it doesn't work
			get cookies() {
				return renderContext.cookies;
			},
			routePattern: this.routeData.route,
			isPrerendered: this.routeData.prerender,
			get clientAddress() {
				return renderContext.getClientAddress();
			},
			get currentLocale() {
				return renderContext.computeCurrentLocale();
			},
			generator: ASTRO_GENERATOR,
			get locals() {
				return renderContext.locals;
			},
			set locals(_) {
				throw new AstroError(AstroErrorData.LocalsReassigned);
			},
			params,
			get preferredLocale() {
				return renderContext.computePreferredLocale();
			},
			get preferredLocaleList() {
				return renderContext.computePreferredLocaleList();
			},
			request: this.request,
			site: pipeline.site,
			url,
			get originPathname() {
				return getOriginPathname(renderContext.request);
			},
			get session() {
				if (this.isPrerendered) {
					pipeline.logger.warn(
						'session',
						`context.session was used when rendering the route ${colors.green(this.routePattern)}, but it is not available on prerendered routes. If you need access to sessions, make sure that the route is server-rendered using \`export const prerender = false;\` or by setting \`output\` to \`"server"\` in your Astro config to make all your routes server-rendered by default. For more information, see https://docs.astro.build/en/guides/sessions/`,
					);
					return undefined;
				}
				if (!renderContext.session) {
					pipeline.logger.warn(
						'session',
						`context.session was used when rendering the route ${colors.green(this.routePattern)}, but no storage configuration was provided. Either configure the storage manually or use an adapter that provides session storage. For more information, see https://docs.astro.build/en/guides/sessions/`,
					);
					return undefined;
				}
				return renderContext.session;
			},
			get csp(): APIContext['csp'] {
				if (!pipeline.manifest.csp) {
					pipeline.logger.warn(
						'csp',
						`context.csp was used when rendering the route ${colors.green(this.routePattern)}, but CSP was not configured. For more information, see https://docs.astro.build/en/reference/experimental-flags/csp/`,
					);
					return undefined;
				}
				return {
					insertDirective(payload) {
						if (renderContext?.result?.directives) {
							renderContext.result.directives = pushDirective(
								renderContext.result.directives,
								payload,
							);
						} else {
							renderContext?.result?.directives.push(payload);
						}
					},
					insertScriptResource(resource) {
						renderContext.result?.scriptResources.push(resource);
					},
					insertStyleResource(resource) {
						renderContext.result?.styleResources.push(resource);
					},
					insertStyleHash(hash) {
						renderContext.result?.styleHashes.push(hash);

Domain

Subdomains

Called By

Frequently Asked Questions

What does createActionAPIContext() do?
createActionAPIContext() is a function in the astro codebase, defined in packages/astro/src/core/render-context.ts.
Where is createActionAPIContext() defined?
createActionAPIContext() is defined in packages/astro/src/core/render-context.ts at line 428.
What does createActionAPIContext() call?
createActionAPIContext() calls 4 function(s): computeCurrentLocale, computePreferredLocale, computePreferredLocaleList, getClientAddress.
What calls createActionAPIContext()?
createActionAPIContext() is called by 1 function(s): render.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free