Skip to content

Commit

Permalink
Add fast command buffer (#5708)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamw2 authored and EisenbergEffect committed May 31, 2022
1 parent b29a748 commit 3622ca0
Show file tree
Hide file tree
Showing 3 changed files with 502 additions and 42 deletions.
89 changes: 47 additions & 42 deletions packages/web-components/fast-ssr/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,55 @@ function handleRequest(req: Request, res: Response) {
});
}

function handleStyleRequest(req: Request, res: Response) {
res.set("Content-Type", "text/html");
fs.readFile(
path.resolve(__dirname, "./src/fast-style/index.fixture.html"),
{ encoding: "utf8" },
(err, data) => {
const stream = (Readable as any).from(data);
stream.on("readable", function (this: any) {
while ((data = this.read())) {
res.write(data);
}
});
stream.on("close", () => res.end());
stream.on("error", (e: Error) => {
console.error(e);
process.exit(1);
});
}
);
}

function handleStyleScriptRequest(req: Request, res: Response) {
res.set("Content-Type", "application/javascript");
fs.readFile(
path.resolve(__dirname, "./dist/esm/fast-style/index.js"),
{ encoding: "utf8" },
(err, data) => {
const stream = (Readable as any).from(data);
stream.on("readable", function (this: any) {
while ((data = this.read())) {
res.write(data);
}
});
stream.on("close", () => res.end());
stream.on("error", (e: Error) => {
console.error(e);
process.exit(1);
});
}
);
function handlePathRequest(
mapPath: string,
contentType: string,
req: Request,
res: Response
) {
res.set("Content-Type", contentType);
fs.readFile(path.resolve(__dirname, mapPath), { encoding: "utf8" }, (err, data) => {
const stream = (Readable as any).from(data);
stream.on("readable", function (this: any) {
while ((data = this.read())) {
res.write(data);
}
});
stream.on("close", () => res.end());
stream.on("error", (e: Error) => {
console.error(e);
process.exit(1);
});
});
}

const app = express();
app.get("/", handleRequest);
app.get("/fast-style", handleStyleRequest);
app.get("/fast-style.js", handleStyleScriptRequest);
app.get("/fast-style", (req: Request, res: Response) =>
handlePathRequest("./src/fast-style/index.fixture.html", "text/html", req, res)
);
app.get("/fast-style.js", (req: Request, res: Response) =>
handlePathRequest(
"./dist/esm/fast-style/index.js",
"application/javascript",
req,
res
)
);
app.get("/fast-command-buffer", (req: Request, res: Response) =>
handlePathRequest(
"./src/fast-command-buffer/index.fixture.html",
"text/html",
req,
res
)
);
app.get("/fast-command-buffer.js", (req: Request, res: Response) =>
handlePathRequest(
"./dist/esm/fast-command-buffer/index.js",
"application/javascript",
req,
res
)
);
app.listen(PORT);
Loading

0 comments on commit 3622ca0

Please sign in to comment.