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

fix: Handle static assets on the rw-serve-fe #10018

Merged
merged 4 commits into from
Feb 16, 2024

Conversation

Josh-Walker-GM
Copy link
Collaborator

Problem
The current rw-serve-fe which is used when you have SSR or RSC enabled does not serve static assets like robots.txt or other files such as fonts, images etc which are placed in web/dist by the yarn rw build process.

This became apparent when I was upgrading the badge app example to the latest canary. The current behaviour is:
image

Whereas the expected behaviour (and the behaviour introduced by the changes here) is:
image

Changes

  1. This adds a final express static handler for the web dist folder. My understanding is that the order is important such that adding this at the end will mean any match that occurs for the previously defined handlers/middlewares will take precedence.
  2. Fixes an unrelated duplicate .default for the build manifest console logging.

Notes
I'm not certain this is the perfect way of doing this but it appears to match the behaviour we support in the non-rsc/ssr version of serve which registers a handler for static assets covering the full dist folder.

I added this as "next-release" just because it felt that way to me but this could be considered a "next-release-patch". Happy for it to be changed.

@Josh-Walker-GM Josh-Walker-GM added the release:fix This PR is a fix label Feb 15, 2024
@Josh-Walker-GM Josh-Walker-GM added this to the next-release milestone Feb 15, 2024
@Josh-Walker-GM Josh-Walker-GM self-assigned this Feb 15, 2024
@@ -175,6 +175,9 @@ export async function runFeServer() {
})
)

// Serve static assets that aren't covered by any of the above routes or middleware
app.use(express.static(rwPaths.web.dist, { index: false }))
Copy link
Collaborator

@dac09 dac09 Feb 16, 2024

Choose a reason for hiding this comment

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

Hey Josh, this looks fine! But could we also get it to ignore everything in the web.dist.server directory?

I'm changing how this stuff will work for rsc builds anyway, but doesn't hurt to be thorough now.

For reference I'm going to go with this folder structure, like we discussed before:

web/dist
├── client
│   ├── README.md
│   ├── assets
│   ├── client-build-manifest.json
│   ├── favicon.png
│   ├── index.html
│   └── robots.txt
├── rsc
│   ├── README.md
│   ├── assets
│   ├── entries.js
│   ├── favicon.png
│   ├── robots.txt
│   └── server-build-manifest.json
└── server
    ├── Document.js
    ├── README.md
    ├── assets
    ├── entry.server.js
    ├── favicon.png
    ├── robots.txt
    └── route-manifest.json

So there's no risk of accidentally leaking code we don't want to!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When you've implemented this nesting I think we will have an easier time only exposing what we intend to. For now, I need to expose it all and then block the server dist.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes exactly.

@dac09 dac09 modified the milestones: next-release, SSR Feb 16, 2024
@dac09
Copy link
Collaborator

dac09 commented Feb 16, 2024

Changed the milestone for consistency. I use SSR so that we can find all these PRs later in one go.

Thanks Josh ☮️

@dac09 dac09 enabled auto-merge (squash) February 16, 2024 09:34
@dac09 dac09 merged commit 4891360 into main Feb 16, 2024
40 checks passed
@dac09 dac09 deleted the jgmw-fix/rw-serve-fe-static-assets branch February 16, 2024 09:46
dac09 added a commit to dac09/redwood that referenced this pull request Feb 16, 2024
* 'main' of github.com:redwoodjs/redwood: (22 commits)
  fix: Handle static assets on the `rw-serve-fe` (redwoodjs#10018)
  fix(server): fix env var loading in `createServer` (redwoodjs#10021)
  fix(deps): remove react types packages from `@redwoodjs/testing` dependencies (redwoodjs#10020)
  chore(release): add back `update-package-versions` task (redwoodjs#10017)
  chore(renovate): Disable for experimental apollo package (redwoodjs#10016)
  RSC: server cells lowercase data function (redwoodjs#10015)
  fix(RSC/SSR): pass CLI options through to apiServerHandler (redwoodjs#10012)
  7.0 RC: Remove hardcoded check for `session.id` (redwoodjs#10013)
  Spelling fix in what-is-redwood.md (redwoodjs#10011)
  Typos in realtime.md (redwoodjs#10010)
  RSC: Server cell smoke tests (redwoodjs#10008)
  RSC: test-project EmptyUser 'use client' cell (redwoodjs#10007)
  RSC: babel-plugin-redwood-cell remove redundant reset (redwoodjs#10006)
  chore(deps): Upgrade to yarn v4.1.0 (redwoodjs#10002)
  fix(docs): Spelling of `data-migrate` command (redwoodjs#10003)
  docs: add aliases fo `type-check` command (redwoodjs#10004)
  RSC: Insert 'use client' in scaffolded components (redwoodjs#9998)
  fix(telemetry): Fix 'destroy' spelling (redwoodjs#10000)
  chore(jsdocs): Fix jsdoc formatting for hover help (redwoodjs#9999)
  bug: Update setupHandler.ts firebase version (redwoodjs#9997)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants