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

Support custom entry.server file in Vercel Vite Preset #89

Merged

Conversation

TooTallNate
Copy link
Member

@TooTallNate TooTallNate commented Mar 9, 2024

Allows for a custom entry.server.jsx/entery.server.tsx file to exist in the project. The following heuristics are used to determine whether or not to copy in the Vercel-specific entry.server file:

  • If there is no entry.server file, then we copy in the Vercel entry server
  • If there is a entry.server file, then we hash the contents to try to determine if the file has been modified from a known default Remix template[1].
    • If there's a hash match, we can safely copy in the Vercel entry server
    • If there's no match, then we run a RegExp on the contents to see if @vercel/remix is being used
      • If no RegExp match, we print a warning and link to docs, but allow the build to continue

[1]: There is a script to generate the JSON file containing the sha256sums of the all Remix templates' entry.server contents throughout the Git history. For now, I just ran the script manually. In the future, we can set up a GH Action to automate updating the JSON file.

To test this out

Install the @vercel/remix package from this URL: https://remix-git-tootallnate-zero-1664-allow-for-custom-entryse-6ab7cd.vercel.sh/vercel-remix.tgz

npm i https://remix-git-tootallnate-zero-1664-allow-for-custom-entryse-6ab7cd.vercel.sh/vercel-remix.tgz

Your customized entry.server file should be based on this starting point:

import { RemixServer } from "@remix-run/react";
import { handleRequest } from "@vercel/remix";

export default function (
  request,
  responseStatusCode,
  responseHeaders,
  remixContext
) {
  let remixServer = <RemixServer context={remixContext} url={request.url} />;
  return handleRequest(
    request,
    responseStatusCode,
    responseHeaders,
    remixServer
  );
}

After that you can deploy to Vercel as usual.

Copy link

vercel bot commented Mar 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
remix ✅ Ready (Inspect) Visit Preview Mar 15, 2024 2:53am

@Gbuomprisco
Copy link

Hi @TooTallNate - this is working for me, thanks for that.

The only issue I encountered is that my index route (which is under the route _site._index.tsx) does not get compiled, resulting in a 404 error.

@TooTallNate
Copy link
Member Author

TooTallNate commented Mar 9, 2024

@Gbuomprisco Could you share a repository demonstrating the 404 issue (ideally in a new issue)?

@TooTallNate TooTallNate marked this pull request as ready for review March 11, 2024 18:05
@Gbuomprisco
Copy link

It seems to work fine in a minimal starter but not with my (largeish) application :| I'll keep testing!

Copy link
Collaborator

@EndangeredMassa EndangeredMassa left a comment

Choose a reason for hiding this comment

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

Is there a test we can write for this?

packages/vercel-remix/vite.ts Outdated Show resolved Hide resolved
packages/vercel-remix/vite.ts Outdated Show resolved Hide resolved
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
@TooTallNate
Copy link
Member Author

@EndangeredMassa Test will be added on the Remix builder side.

…' of github.com:vercel/remix into tootallnate/zero-1664-allow-for-custom-entryserver-file
@TooTallNate TooTallNate merged commit 283fb95 into main Mar 15, 2024
2 checks passed
@TooTallNate TooTallNate deleted the tootallnate/zero-1664-allow-for-custom-entryserver-file branch March 15, 2024 02:54
kodiakhq bot pushed a commit to vercel/vercel that referenced this pull request Apr 10, 2024
Adds an e2e test fixture which tests that a custom `app/entry.server` file is supported.

Related to:

* vercel/remix#85
* vercel/remix#89
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.

None yet

3 participants