Skip to content

Commit 0189734

Browse files
committed
wip
This seems close but I'm not really sure how to define the "handle document request" function? it seems like it's kinda sorta split between app/entry.server and app/index, where entry.server defines a rendering function and index actually listens for requests. But the express renderer isn't returning a response correctly
1 parent 1239942 commit 0189734

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

app/entry.server.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import "react-router";
22
import { createRequestHandler } from "@react-router/express";
33
import express from "express";
44

5-
export const app = express();
6-
console.log("entrypoint.server");
7-
app.use(
8-
createRequestHandler({
9-
// @ts-expect-error - virtual module provided by React Router at build time
10-
build: () => import("virtual:react-router/server-build"),
11-
}),
12-
);
5+
export const handleRequest = createRequestHandler({
6+
// @ts-expect-error - virtual module provided by React Router at build time
7+
build: () => import("virtual:react-router/server-build"),
8+
});
9+
10+
const app = express();
11+
app.use(handleRequest);
12+
13+
export default app;

app/index.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,18 @@ if (isProd()) {
5050
server: { middlewareMode: true },
5151
}),
5252
);
53-
console.log({ viteDevServer });
5453
app.use(viteDevServer.middlewares);
55-
app.use(async (req, res, next) => {
56-
try {
57-
const source = await viteDevServer.ssrLoadModule(
58-
"./app/entry.server.tsx",
59-
);
60-
const out = await source.app(req, res, next);
61-
console.log(out);
62-
return out;
63-
} catch (error) {
64-
console.log({ error });
54+
viteDevServer
55+
.ssrLoadModule("./app/entry.server.tsx")
56+
.then((source) => {
57+
app.use(source.default);
58+
})
59+
.catch((error) => {
6560
if (typeof error === "object" && error instanceof Error) {
6661
viteDevServer.ssrFixStacktrace(error);
6762
}
68-
next(error);
69-
}
70-
});
63+
console.log({ error });
64+
});
7165
}
7266
app.use(express.static("build/client", { maxAge: "1h" }));
7367

0 commit comments

Comments
 (0)