Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-server): custom react server entry #199

Merged
merged 6 commits into from
Mar 17, 2024

Conversation

hi-ogawa
Copy link
Owner

@hi-ogawa hi-ogawa commented Mar 17, 2024

This allows extending react-server side server code, for example:

//
// src/entry-react-server.tsx
//
import {
  type ReactServerHandler,
  handler as baseHandler,
} from "@hiogawa/react-server/entry-react-server";

export const handler: ReactServerHandler = async (ctx) => {
  // handle trpc request https://trpc.io/docs/server/adapters/fetch
  const url = new URL(ctx.request.url);
  if (url.pathname.startsWith("/__trpc/")) {
    return new Response("...");
  }

  // run server action/component handler with custom async context
  // https://nodejs.org/api/async_context.html#class-asynclocalstorage
  return myAsyncContext.run({ ... }, () => baseHandler(ctx));
};

//
// vite.config.ts
//
export default defineConfig({
  plugins: [
    vitePluginReactServer({
      entry: "/src/entry-react-server.tsx",
    }),
  ],
  ...
});

TODO

  • demo
  • test

@hi-ogawa hi-ogawa mentioned this pull request Mar 17, 2024
69 tasks
@hi-ogawa hi-ogawa marked this pull request as ready for review March 17, 2024 02:43
@hi-ogawa hi-ogawa merged commit 2df1569 into main Mar 17, 2024
4 checks passed
@hi-ogawa hi-ogawa deleted the feat-react-server-custom-entry branch March 17, 2024 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant