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

Update middleware docs #1010

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

amirhhashemi
Copy link
Contributor

  • I have read the Contribution guide
  • This PR references an issue (except for typos, broken links, or other minor problems)

Description(required)

This is a work in progress. However, I'm open for suggestions and feedback

This PR adds comprehensive documentation for middleware. Please refer to this Discord thread for additional background and discussion regarding this PR.

It follows the explanation guide from the Diátaxis framework, as this fits better with the other related pages. I focused on the theoretical aspects of middleware and avoided too much practical detail to reduce overlap with reference and guide pages.

There are a few practical examples that may be significant enough to be part of a how-to guide, especially the CORS example. I wasn't sure where to place these examples, so I have included them here for now.

TODO

  • Add a basic example of using middleware. Like a mini tutorial. Something similar to what Astro is doing. This doesn't quite fit into the explanation guide of the Diátaxis framework, but since we don't have a dedicated tutorial section yet, I believe it's beneficial to include some tutorial aspects on this page.
  • Move the CORS example to a guide page.
  • Add a section about sending custom responses. This could include generalizing the "Redirects" section, as redirecting in middleware is a form of sending a custom response.

Related issues & labels

Copy link

stackblitz bot commented Jan 9, 2025

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

netlify bot commented Jan 9, 2025

Deploy Preview for solid-docs ready!

Name Link
🔨 Latest commit 1c210d3
🔍 Latest deploy log https://app.netlify.com/sites/solid-docs/deploys/678125fe44652d00071e5019
😎 Deploy Preview https://deploy-preview-1010--solid-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -2,28 +2,227 @@
title: "Middleware"
---

Middlewares may be included by passing file you specify in your start config.
Middleware is a function that intercepts HTTP requests and responses. It allows you to modify the response by rewriting, redirecting, modifying the request or response headers, or responding directly.
Copy link
Contributor

Choose a reason for hiding this comment

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

It allows you to modify the response by rewriting, redirecting, modifying the request or response headers, or responding directly.

Feels a little too wordy, maybe split it into multiple sentences or a bullet list, or simplify the list to only mention the broad categories of things, like

It allows you to modify the request or response objects in various ways.

Comment on lines +221 to +227

Although using middleware for authentication and authorization is a common practice in many web frameworks, it is not advisable to use SolidStart middleware for these purposes.

This is because SolidStart middleware is not guaranteed to run on every single request.

For optimal security, all checks should be performed as close to your data source as possible.
Copy link
Contributor

Choose a reason for hiding this comment

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

You can actually add a section on Authentication that shows how to do token validation in a middleware, and reword this to something like this

Using middleware for protecting routes is not recommended in SolidStart. Authorization should be handled as close as possible to the data source.

Technically authentication is completely fine (and recommended) in the middleware, authorization is the thing that should be close to the data and not in the middleware.

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.

[Content]: The middleware page says that you can chain middleware but does not show how.
2 participants