Skip to content

Commit

Permalink
inline node request handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Feb 14, 2024
1 parent 6e9ccec commit 9d262c1
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions packages/remix-dev/vite/cloudflare-proxy-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,19 @@ export const cloudflareProxyVitePlugin = <
let context = { cloudflare };
return () => {
if (!viteDevServer.config.server.middlewareMode) {
viteDevServer.middlewares.use(async (req, res, next) => {
viteDevServer.middlewares.use(async (nodeReq, nodeRes, next) => {
try {
let build = (await viteDevServer.ssrLoadModule(
serverBuildId
)) as ServerBuild;

let handler = createRequestHandler(build, "development");
let nodeHandler: NodeRequestHandler = async (
nodeReq,
nodeRes
) => {
let request = fromNodeRequest(nodeReq);
let loadContext = options.getLoadContext
? await options.getLoadContext({ request, context })
: context;
let res = await handler(request, loadContext);
await toNodeRequest(res, nodeRes);
};
await nodeHandler(req, res);
let req = fromNodeRequest(nodeReq);
let loadContext = options.getLoadContext
? await options.getLoadContext({ request: req, context })
: context;
let res = await handler(req, loadContext);
await toNodeRequest(res, nodeRes);
} catch (error) {
next(error);
}
Expand Down

0 comments on commit 9d262c1

Please sign in to comment.