[ci] format
This commit is contained in:
parent
3daaf510ea
commit
69c955b2bf
5 changed files with 70 additions and 70 deletions
|
@ -83,9 +83,7 @@ export interface RenderOptions {
|
||||||
request: Request;
|
request: Request;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function render(
|
export async function render(opts: RenderOptions): Promise<Response> {
|
||||||
opts: RenderOptions
|
|
||||||
): Promise<Response> {
|
|
||||||
const {
|
const {
|
||||||
links,
|
links,
|
||||||
styles,
|
styles,
|
||||||
|
|
|
@ -632,7 +632,9 @@ export async function renderToIterable(
|
||||||
const Component = await componentFactory(result, props, children);
|
const Component = await componentFactory(result, props, children);
|
||||||
|
|
||||||
if (!isAstroComponent(Component)) {
|
if (!isAstroComponent(Component)) {
|
||||||
console.warn(`Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.`);
|
console.warn(
|
||||||
|
`Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.`
|
||||||
|
);
|
||||||
const response: Response = Component;
|
const response: Response = Component;
|
||||||
throw response;
|
throw response;
|
||||||
}
|
}
|
||||||
|
@ -669,7 +671,7 @@ export async function renderPage(
|
||||||
controller.close();
|
controller.close();
|
||||||
}
|
}
|
||||||
read();
|
read();
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
let init = result.response;
|
let init = result.response;
|
||||||
let response = createResponse(stream, init);
|
let response = createResponse(stream, init);
|
||||||
|
@ -716,7 +718,9 @@ export function maybeRenderHead(result: SSRResult): string | Promise<string> {
|
||||||
return renderHead(result);
|
return renderHead(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function * renderAstroComponent(component: InstanceType<typeof AstroComponent>): AsyncIterable<string> {
|
export async function* renderAstroComponent(
|
||||||
|
component: InstanceType<typeof AstroComponent>
|
||||||
|
): AsyncIterable<string> {
|
||||||
for await (const value of component) {
|
for await (const value of component) {
|
||||||
if (value || value === 0) {
|
if (value || value === 0) {
|
||||||
for await (const chunk of _render(value)) {
|
for await (const chunk of _render(value)) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
const isNodeJS =
|
||||||
const isNodeJS = typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]';
|
typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]';
|
||||||
|
|
||||||
let StreamingCompatibleResponse: typeof Response | undefined;
|
let StreamingCompatibleResponse: typeof Response | undefined;
|
||||||
|
|
||||||
|
@ -56,16 +56,18 @@ function createResponseClass() {
|
||||||
}
|
}
|
||||||
return super.arrayBuffer();
|
return super.arrayBuffer();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return StreamingCompatibleResponse;
|
return StreamingCompatibleResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateResponseFn = (body?: BodyInit | null, init?: ResponseInit) => Response;
|
type CreateResponseFn = (body?: BodyInit | null, init?: ResponseInit) => Response;
|
||||||
|
|
||||||
export const createResponse: CreateResponseFn = isNodeJS ? (body, init) => {
|
export const createResponse: CreateResponseFn = isNodeJS
|
||||||
|
? (body, init) => {
|
||||||
if (typeof StreamingCompatibleResponse === 'undefined') {
|
if (typeof StreamingCompatibleResponse === 'undefined') {
|
||||||
return new (createResponseClass())(body, init);
|
return new (createResponseClass())(body, init);
|
||||||
}
|
}
|
||||||
return new StreamingCompatibleResponse(body, init);
|
return new StreamingCompatibleResponse(body, init);
|
||||||
} : (body, init) => new Response(body, init);
|
}
|
||||||
|
: (body, init) => new Response(body, init);
|
||||||
|
|
|
@ -98,10 +98,7 @@ async function writeWebResponse(res: http.ServerResponse, webResponse: Response)
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeSSRResult(
|
async function writeSSRResult(webResponse: Response, res: http.ServerResponse) {
|
||||||
webResponse: Response,
|
|
||||||
res: http.ServerResponse
|
|
||||||
) {
|
|
||||||
return writeWebResponse(res, webResponse);
|
return writeWebResponse(res, webResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { expect } from 'chai';
|
||||||
import testAdapter from './test-adapter.js';
|
import testAdapter from './test-adapter.js';
|
||||||
import * as cheerio from 'cheerio';
|
import * as cheerio from 'cheerio';
|
||||||
|
|
||||||
|
|
||||||
describe('Streaming', () => {
|
describe('Streaming', () => {
|
||||||
if (isWindows) return;
|
if (isWindows) return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue