Skip to content

Commit

Permalink
Build to a single file (#2873)
Browse files Browse the repository at this point in the history
* Build to a single file

* Updates based on initial code review

* Adds a changeset

* Use the default export for cjs module

* Await generatePages

* Prevent timing from causing module to not import

* Fix shared CSS

* Properly handle windows ids

* Dont shadow

* Fix ts errors

* Remove console.log
  • Loading branch information
matthewp authored Mar 24, 2022
1 parent 79e6f10 commit f478553
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/adapters/node/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SSRManifest } from 'astro';
import type { IncomingMessage, ServerResponse } from 'http';
import type { Readable } from 'stream';
import { NodeApp } from 'astro/app/node';
import { polyfill } from '@astrojs/webapi';

Expand All @@ -8,7 +9,7 @@ polyfill(globalThis, {
});

export function createExports(manifest: SSRManifest) {
const app = new NodeApp(manifest, new URL(import.meta.url));
const app = new NodeApp(manifest);
return {
async handler(req: IncomingMessage, res: ServerResponse, next?: (err?: unknown) => void) {
const route = app.match(req);
Expand All @@ -35,13 +36,8 @@ async function writeWebResponse(res: ServerResponse, webResponse: Response) {
const { status, headers, body } = webResponse;
res.writeHead(status, Object.fromEntries(headers.entries()));
if (body) {
const reader = body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
if (value) {
res.write(value);
}
for await(const chunk of (body as unknown as Readable)) {
res.write(chunk);
}
}
res.end();
Expand Down

0 comments on commit f478553

Please sign in to comment.