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

Handle root favicon requests #4241

Merged
merged 1 commit into from
Sep 25, 2024
Merged

Handle root favicon requests #4241

merged 1 commit into from
Sep 25, 2024

Conversation

KludgeKML
Copy link
Contributor

@KludgeKML KludgeKML commented Sep 24, 2024

This allows us to move the /favicon special route from static to frontend, removing the icon redirect controller from static in preparation for its retirement.

  • Remove favicon.ico in public directory as it's not copied to the S3 bucket and it short-circuits matching the route.
  • Route high up in the routes file so that we don't have to check for/load a content item to do this redirect.

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4241 September 24, 2024 11:50 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4241 September 24, 2024 11:55 Inactive
This allows us to move the /favicon special route from static to frontend, removing the icon redirect controller from static in preparation for its retirement.

- Remove favicon.ico in public directory as it's not copied to
  the S3 bucket and it short-circuits matching the route.
- Route high up in the routes file so that we don't have to check
  for/load a content item to do this redirect.
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4241 September 24, 2024 12:00 Inactive
before_action { expires_in(1.day, public: true) }

def redirect_to_asset
redirect_to(view_context.asset_path("favicon.ico"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I can't keep this in my head it's so complicated!

How does Frontend know where to get that asset from? I would expect there to be an asset called favicon.ico in the assets directory. But there isn't, and I know that the favicon is in the gem. How is this wired up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the app compiles its assets, it includes the assets from the gem. So the app has a sprockets manifest that maps a logical name "favicon.ico" to the fingerprinted asset name ("/assets/frontend/favicon-121ab2(etc).ico"). When you ask for the logical name using .asset_path, it looks up the fingerprinted name in the sprockets manifest.

So here we're saying "if someone asks for /favicon.ico, permanently redirect them to /assets/frontend/favicon-be123a(etc).ico".

Here's the same code in Static https://github.com/alphagov/static/blob/main/app/controllers/icon_redirects_controller.rb (where it's doing exactly the same thing, but obviously to "/assets/static/favicon-(blahblah).ico").

Copy link
Contributor

Choose a reason for hiding this comment

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

So will you merge this, and then update the Route in Router API, and then remove the controller from static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. This merge first, to let frontend do what static was doing, then an update to publishing-api (new home of special routes as of yesterday) to allow us to point favicon.ico at frontend in the router, then a final update to static to remove the controller/publishing_api tasks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem!

@KludgeKML KludgeKML merged commit bca270f into main Sep 25, 2024
12 checks passed
@KludgeKML KludgeKML deleted the handle-favicon branch September 25, 2024 08:51
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