Replies: 1 comment 2 replies
-
I'm not sure I understand the proposal... For example, you can already type locals: https://docs.astro.build/en/guides/middleware/#middleware-types |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Proposal: Provide an official, documented pattern or direct support in Astro for injecting custom object instances (e.g., an Axios client) into
APIContext
/ActionAPIContext
.Background & Motivation
Users often need to share dependencies—like HTTP clients, database connections, logging utilities, etc.—between middleware, actions, and API routes. Right now, the general recommendation is to attach these instances to
ctx.locals
. While this works, it can feel awkward and may lack clarity or best-practice guidance:locals
.By providing a documented way (or built-in mechanism) to attach shared instances, Astro could simplify this common use case and encourage consistent patterns.
Goals
APIContext
/ActionAPIContext
.Example
Here’s one potential usage concept:
This example highlights a more direct, typed pattern for shared services, as opposed to just dropping objects onto ctx.locals. The goal is not to force a specific naming convention (services vs. locals), but rather to have a clear, consistent, and documented approach that Astro users can adopt.
Beta Was this translation helpful? Give feedback.
All reactions