-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor rendering for testing (#5071)
* Refactor rendering for testing * Correctly pass the mod for endpoints
- Loading branch information
Showing
18 changed files
with
497 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import type { EndpointHandler } from '../../../@types/astro'; | ||
import type { SSROptions } from '../../render/dev'; | ||
import { preload } from '../../render/dev/index.js'; | ||
import { createRenderContext } from '../../render/index.js'; | ||
import { call as callEndpoint } from '../index.js'; | ||
|
||
export async function call(ssrOpts: SSROptions) { | ||
const [, mod] = await preload(ssrOpts); | ||
return await callEndpoint(mod as unknown as EndpointHandler, { | ||
...ssrOpts, | ||
ssr: ssrOpts.settings.config.output === 'server', | ||
site: ssrOpts.settings.config.site, | ||
adapterName: ssrOpts.settings.config.adapter?.name, | ||
export async function call(options: SSROptions) { | ||
const { env, preload: [,mod] } = options; | ||
const endpointHandler = mod as unknown as EndpointHandler; | ||
|
||
const ctx = createRenderContext({ | ||
request: options.request, | ||
origin: options.origin, | ||
pathname: options.pathname, | ||
route: options.route | ||
}); | ||
|
||
return await callEndpoint(endpointHandler, env, ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark'; | ||
import type { | ||
ComponentInstance, | ||
Params, | ||
Props, | ||
RouteData, | ||
RuntimeMode, | ||
SSRElement, | ||
SSRLoadedRenderer, | ||
} from '../../@types/astro'; | ||
import type { LogOptions } from '../logger/core.js'; | ||
import type { Environment } from './environment.js'; | ||
|
||
/** | ||
* The RenderContext represents the parts of rendering that are specific to one request. | ||
*/ | ||
export interface RenderContext { | ||
request: Request; | ||
origin: string; | ||
pathname: string; | ||
url: URL; | ||
scripts?: Set<SSRElement>; | ||
links?: Set<SSRElement>; | ||
styles?: Set<SSRElement>; | ||
route?: RouteData; | ||
status?: number; | ||
} | ||
|
||
export type CreateRenderContextArgs = Partial<RenderContext> & { | ||
origin?: string; | ||
request: RenderContext['request']; | ||
} | ||
|
||
export function createRenderContext(options: CreateRenderContextArgs): RenderContext { | ||
const request = options.request; | ||
const url = new URL(request.url); | ||
const origin = options.origin ?? url.origin; | ||
const pathname = options.pathname ?? url.pathname; | ||
return { | ||
...options, | ||
origin, | ||
pathname, | ||
url | ||
}; | ||
} |
Oops, something went wrong.