Skip to content

[remix] Add support for custom server entrypoint in React Router apps - #13043

Merged
TooTallNate merged 3 commits into
mainfrom
tootallnate/zero-3271-add-support-for-custom-server-entrypoints
Feb 11, 2025
Merged

TooTallNate merged 3 commits into
mainfrom
tootallnate/zero-3271-add-support-for-custom-server-entrypoints

Conversation

@TooTallNate

@TooTallNate TooTallNate commented Feb 10, 2025 •

Copy link
Copy Markdown
Member

Adds support for custom server entrypoint for React Router applications, when using the Vite build.rollupOptions.input configuration property. This allows for defining a custom "load context" for each HTTP request as well as integration with other desired frameworks.

The default export of the entrypoint is expected to be a Web API-compatible function ((req: Request) => Response). For example, to integrate React Router with a Hono server entrypoint:

// vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig(({ isSsrBuild }) => ({
  build: {
    rollupOptions: isSsrBuild
      ? {
        // Important! The file path to the server entrypoint
        input: "./server/app.ts",
      }
      : undefined,
  },
  plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
}));
// server/app.ts
import { Hono } from "hono";
import { createRequestHandler } from "react-router";

// @ts-expect-error - virtual module provided by React Router at build time
import * as build from "virtual:react-router/server-build";

declare module "react-router" {
    interface AppLoadContext {
        VALUE_FROM_HONO: string;
    }
}

const app = new Hono();

// Add any additional Hono configuration / middleware here

const handler = createRequestHandler(build);
app.mount("/", (req) => handler(req, {
    // This is the custom "load context", which can
    // be modified on a per-Request basis
    VALUE_FROM_HONO: "Hello from Hono"
}));

export default app.fetch;

@changeset-bot

changeset-bot Bot commented Feb 10, 2025 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d660ef8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@vercel/remix-builder Minor
vercel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@socket-security

Copy link
Copy Markdown

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None 0 1.13 MB yusukebe

View full report↗︎

@TooTallNate
TooTallNate added this pull request to the merge queue Feb 11, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 11, 2025
@TooTallNate
TooTallNate added this pull request to the merge queue Feb 11, 2025
Merged via the queue into main with commit 7e1ee69 Feb 11, 2025
@TooTallNate
TooTallNate deleted the tootallnate/zero-3271-add-support-for-custom-server-entrypoints branch February 11, 2025 19:32
import { createRequestHandler } from 'react-router';
import * as build from 'ENTRYPOINT_PLACEHOLDER';
export default createRequestHandler(build.default || build);
import * as build_ from 'virtual:react-router/server-build';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LukeSheard pushed a commit that referenced this pull request Feb 11, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/[email protected]

### Minor Changes

- Support process tracing
([#12894](#12894))

## [email protected]

### Minor Changes

- Support process tracing
([#12894](#12894))

### Patch Changes

- Fixed bug where rewrites would be applied twice in some cases
([#13040](#13040))

- Updated dependencies
\[[`cc0b7194b119f72f59f77f9fba7e7a1188dac03c`](cc0b719),
[`7e1ee69be35db77d7692c07f5eab255ce24399de`](7e1ee69),
[`1f1186f26c6189c36098c76e3acda69ccb1790e0`](1f1186f),
[`6a4c779704d777e11370a19df5bcba168dd6dd48`](6a4c779)]:
    -   @vercel/[email protected]
    -   @vercel/[email protected]
    -   @vercel/[email protected]
    -   @vercel/[email protected]
    -   @vercel/[email protected]

## @vercel/[email protected]

### Minor Changes

- Support process tracing
([#12894](#12894))

### Patch Changes

- Fixed bug where rewrites would be applied twice in some cases
([#13040](#13040))

- pin fixtures and set up auto updates
([#12979](#12979))

## @vercel/[email protected]

### Minor Changes

- Add support for custom server entrypoint in React Router apps
([#13043](#13043))

## @vercel/[email protected]

### Patch Changes

- Updated dependencies
\[[`cc0b7194b119f72f59f77f9fba7e7a1188dac03c`](cc0b719)]:
    -   @vercel/[email protected]

## @vercel/[email protected]

### Patch Changes

- Updated dependencies
\[[`cc0b7194b119f72f59f77f9fba7e7a1188dac03c`](cc0b719)]:
    -   @vercel/[email protected]

## @vercel/[email protected]

### Patch Changes

- Updated dependencies
\[[`cc0b7194b119f72f59f77f9fba7e7a1188dac03c`](cc0b719)]:
    -   @vercel/[email protected]

## @vercel/[email protected]

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
QuietCraftsmanship pushed a commit to QuietCraftsmanship/Vercel that referenced this pull request Jul 6, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/[email protected]

### Minor Changes

- Support process tracing
([#12894](vercel/vercel#12894))

## [email protected]

### Minor Changes

- Support process tracing
([#12894](vercel/vercel#12894))

### Patch Changes

- Fixed bug where rewrites would be applied twice in some cases
([#13040](vercel/vercel#13040))

- Updated dependencies
\[[`90dd70d026529fe592da78492536a83658432283`](vercel/vercel@90dd70d),
[`0d025a1fe736563b876df7619e750e1552ac2ad3`](vercel/vercel@0d025a1),
[`b4110af6ee40e3c0f617f38e1194c0ac6b8852e3`](vercel/vercel@b4110af),
[`a3b803f90bd4fd3e81a52b44e118923ef7a110ad`](vercel/vercel@a3b803f)]:
    -   @vercel/[email protected]
    -   @vercel/[email protected]
    -   @vercel/[email protected]
    -   @vercel/[email protected]
    -   @vercel/[email protected]

## @vercel/[email protected]

### Minor Changes

- Support process tracing
([#12894](vercel/vercel#12894))

### Patch Changes

- Fixed bug where rewrites would be applied twice in some cases
([#13040](vercel/vercel#13040))

- pin fixtures and set up auto updates
([#12979](vercel/vercel#12979))

## @vercel/[email protected]

### Minor Changes

- Add support for custom server entrypoint in React Router apps
([#13043](vercel/vercel#13043))

## @vercel/[email protected]

### Patch Changes

- Updated dependencies
\[[`90dd70d026529fe592da78492536a83658432283`](vercel/vercel@90dd70d)]:
    -   @vercel/[email protected]

## @vercel/[email protected]

### Patch Changes

- Updated dependencies
\[[`90dd70d026529fe592da78492536a83658432283`](vercel/vercel@90dd70d)]:
    -   @vercel/[email protected]

## @vercel/[email protected]

### Patch Changes

- Updated dependencies
\[[`90dd70d026529fe592da78492536a83658432283`](vercel/vercel@90dd70d)]:
    -   @vercel/[email protected]

## @vercel/[email protected]

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview — d660ef8b Deployed Feb 11, 2025 by vercel[bot]
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.

3 participants