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: Add appropriate response headers to SPA entry point HTML response #6992

Merged
merged 2 commits into from May 15, 2024

Conversation

zapplebee
Copy link
Contributor

About the changes

Current state, when returning the HTML entry point from the server, there are no headers attached. We encountered an issue with a deployment and this had an impact for us.

A brief description:

  1. We deployed the most recent version. Noticed an unrelated issue.
  2. Users tried to use the most recent version and due to their client cache, requested assets that did not exist in the newest version.
  3. Our cache layer cached the assets that were not there with the HTML response. It had to infer the type based on the filename because there was no attached Content-Type header. This cache was very sticky.
  4. After rolling back we saw the HTML response (from the cache) instead of the appropriate response from the upstream Unleash application.

This PR does a few things.

  1. When responding with the HTML entry point, it adds header (Content-Type: text/html).
  2. When the client is requesting an asset (a path that ends with an extension), it also instructs the resource not to be cached (Cache-Control: no-cache) and returns a 404. This will prevent misses from getting cached.

Closes #

No open issue.

Important files

Discussion points

To me, there doesn't seem to be a lot of test infra on serving the SPA application. If that is an error, please indicate where that is and an appropriate test can be added.

Copy link

vercel bot commented May 6, 2024

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

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview May 6, 2024 6:04pm

Copy link

vercel bot commented May 6, 2024

@zapplebee is attempting to deploy a commit to the unleash-team Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 1 findings(s) 🚩

View detailed results in CodeScene

@@ -201,6 +201,7 @@ export default async function getApp(
}

app.get(`${baseUriPath}`, (req, res) => {
res.set('Content-Type', 'text/html');

Choose a reason for hiding this comment

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

❌ Getting worse: Complex Method
getApp increases in cyclomatic complexity from 23 to 25, threshold = 9

Suppress

@zapplebee zapplebee changed the title Add appropriate response headers to SPA entry point HTML response fix: Add appropriate response headers to SPA entry point HTML response May 6, 2024
@chriswk chriswk self-requested a review May 15, 2024 07:35
Copy link
Contributor

@chriswk chriswk left a comment

Choose a reason for hiding this comment

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

Thank you for adding this. I'm going to merge this, and it will be part of our next release.

@chriswk chriswk merged commit 9903cf1 into Unleash:main May 15, 2024
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants