Comments (4)
Thank you for the issue, maybe we could try to keep the code examples as simple as possible and avoid destructuring?
At least in the first code example, the text above it becomes easier to understand:
Inside this file, export an onRequest() function that can be passed a context object and next() function. This must not be a default export.
export function onRequest (context, next) {
...
}
from docs.
I don't get your point, the two pages perfectly agree with each other. Which part is confusing you?
Is it because in the Astro example context
is being destructured?
from docs.
I don't get your point too.
Could you please explain the meaning of 'context' within the term 'context.locals'?
What is the difference between context.locals
and just write locals
?
from docs.
There is no difference.
context
is how the first argument of the middleware is called (the type is called APIContext
). Same for API Endpoints.
// This
export const onRequest = (context, next) => {
const locals = context.locals;
locals.foo = 'bar';
};
// Is the same as this
export const onRequest = ({ locals }, next) => {
locals.foo = 'bar';
};
It is just a more compact JS syntax called destructuring which can be used in many places including function parameters
from docs.
Related Issues (20)
- ⚠️ Issue - The implementation of themes from Shiki is not working properly. HOT 1
- Add a bit more help text to client:only description
- Give us feedback form Appearance is not in line with Astro Doc Styling HOT 1
- RTL Docs `Inline Code Snippet` need to be always LTR. HOT 4
- Prettier plugin content is incorrect. HOT 2
- Middleware: unclear that reading cookies/headers behaviour HOT 1
- Improve documentation on fallback content for slots HOT 3
- Unclear refactoring task
- Script Tag CDNs with View Transitions HOT 1
- `prose-p:text-justify` makes recipe less usable HOT 1
- ⚠️ Issue @astro/mdx keeps crushing due to rehype dependency HOT 3
- Document `?url` usage in Imports docs HOT 2
- Tutorial says that the rss.xml can't be seen in development but it actually can be HOT 2
- There are many ways to create a blog with Astro. How to choose one? HOT 1
- ⚠️ Issue: Cannot find module '/app/dist/server/entry.mjs' HOT 1
- Add a tip telling the user that anchor elements are not affected by base config
- ⚠️ Issue, error in Foreign key in schema HOT 1
- Missing results for query "rtl" HOT 4
- View transitions flicker HOT 2
- Docs doesn't specify that `import.meta.env` is evaluated at build time with SSR adapter. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.