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

refactor: middleware as atomic files + docs #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jbmoelker
Copy link
Member

@jbmoelker jbmoelker commented Dec 5, 2024

l# Changes

Refactors middleware to atomic files (src/middleware/...), so middleware stays maintainable when adding more (like the upcoming file proxy middleware) and has a structure suitable to add tests to (in src/middleware/tests/ like done in src/lib/datocms/tests/).

Associated issue

N/A

How to test

  1. Open preview link
  2. Verify the different middleware handlers (i18n, redirects) still work (preview can't be tested on deploy preview, unless we list it as a preview branch; datocms is hard to check on deploy preview)
  3. Run locally
  4. Verify the different middleware handlers (datocms, i18n, preview, redirects) still work

Checklist

  • I have performed a self-review of my own code
  • I have made sure that my PR is easy to review (not too big, includes comments)
  • I have made updated relevant documentation files (in project README, docs/, etc)
  • I have added a decision log entry if the change affects the architecture or changes a significant technology
  • I have notified a reviewer

so middleware stays maintainable when adding more (like the upcoming file proxy middleware) and has a structure suitable to add tests/ to.
Copy link

cloudflare-workers-and-pages bot commented Dec 28, 2024

Deploying head-start with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9137a28
Status: ✅  Deploy successful!
Preview URL: https://da72b2f5.head-start.pages.dev
Branch Preview URL: https://refactor-middleware-atomic-f.head-start.pages.dev

View logs

@jbmoelker jbmoelker marked this pull request as ready for review December 28, 2024 20:00
@@ -2,6 +2,10 @@

**Head Start leverages [Astro file-based routing](https://docs.astro.build/en/core-concepts/routing/#_top) combined with Cloudflare features for redirects and page not found behaviour. The setup is enhanced with i18n routing, API routing, nested page routing and helpers to resolve routes.**

## Routing middleware
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we also add middleware/ to project-structure.md?

Copy link
Contributor

@jurgenbelien jurgenbelien left a comment

Choose a reason for hiding this comment

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

Looks good, mentioned @sjoerdbeentjes for adding a caveat do the docs, but I feel it is not strictly necessary.

import { preview } from './preview';
import { redirects } from './redirects';


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

@@ -0,0 +1,3 @@
# Middleware

**[Astro supports middleware](https://docs.astro.build/en/guides/middleware/) that allows you to intercept requests and responses and inject behaviors dynamically every time a page or endpoint is about to be rendered.**
Copy link
Contributor

Choose a reason for hiding this comment

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

@sjoerdbeentjes you recently mentioned the caveat that when home resolves as a static file, middleware will not run. Perhaps it is wise to explicitly add this here.

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.

2 participants