Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
Bundle ssr output into single file
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jun 1, 2022
1 parent 2421871 commit 2fafc3b
Show file tree
Hide file tree
Showing 15 changed files with 2,209 additions and 434 deletions.
22 changes: 2 additions & 20 deletions examples/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
import express from "express";
import { fromNodeRequest } from "@borderless/site/node";
import { createHandler } from "@borderless/site/adapters/node";
import { server } from "./dist/server/server.js";

const app = express();

app.use(express.static("dist/client"));

app.get("*", async (req, res, next) => {
try {
const response = await server(fromNodeRequest(req), {});

for (const [key, value] of response.headers.entries()) {
res.setHeader(key, value);
}

if (typeof response.body === "object") {
const stream = await response.body.nodeStream();
stream.pipe(res);
} else {
res.end(response.body);
}
} catch (err) {
next(err);
}
});
app.use(createHandler(server, () => undefined));

app.listen(3000, () => console.log(`Server running at http://localhost:3000`));
Loading

0 comments on commit 2fafc3b

Please sign in to comment.