This is demo of how you can use the fact that Remix provides you with a real server to send one response to web browsers and another response to a curl
client.
This demo is deployed to Vercel
and can be viewed in a web browser at https://remix-curl.vercel.app/
Alternatively, you can curl this same url with:
curl --silent https://remix-curl.vercel.app
to see how this site sends a completely different response to curl
, and in fact, the response to curl
takes advantage of the fact that it's being called from a terminal and the plaintext response includes ansi style escape codes so that you get a pretty output in the terminal just like you do in the browser!
-
As of this writing (April 5th, 2022), Remix doesn't support configuring
esbuild
with customexternal
modules (may be fixed if they merge remix-run/remix#1841). Unfortunately in addition to this, theexternal
modules declared internally by Remix are the Node built-ins (process
,fs
, etc) but only those without thenode:
specifier prefix, which means any 3rd party dependency that references e.g.node:process
(or any other Node built-in via itsnode:
prefixed specifier) will cause a build error.Since I wanted to use the boxen module by @sindresorhus in the
curl
response text, and this module referencesnode:process
, I needed to usepatch-package
as a quick way to ensure that the un-prefixed Node built-in was being referenced byboxen
.If at some point either:
- Remix includes both
node:
prefixed and unprefixed Node built-ins in their list ofexternal
modules foresbuild
, OR - Remix allows users to supply their own
external
module list via configuration
then this use of
patch-package
can go away. - Remix includes both
https://blog.andrewbrey.com/2022-04-05-building-a-curl-able-developer-resume-site-with-remix