-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Env vriables with Vite and Cloudflare, the new replace of getRuntime() #8060
Comments
Ah, I think this consideration was overlooked when switching to |
@Mahmoudgalalz |
I think @Mahmoudgalalz is saying that this is untyped. To type the locals you do this: https://docs.astro.build/en/guides/middleware/#middleware-types |
I have a similar question, how can I access my cloudflare env variables at my API endpoint on the server? Docs say,
But since getRuntime is gone, how do I access the env? |
Probably we should write a better documentation. Inside an const runtime = Astro.locals.runtime; Inside an endpoint export function get(context) {
const runtime = context.locals.getRuntime();
} |
@ematipico this is the error I'm getting from ts, Also, I'm planning to do this, is this correct? |
My bad, it should be just |
There doesn't seem to be anything in runtime |
Could you provide a Minimal Reproducible Example? |
It does work for me (https://github.com/alexanderniebuhr/smoggy-spiral), maybe you can either provide a Minimal Reproducible Example or compare the difference to your code. Also note, if you try to get it working with |
Is it possible you checked that while running the Dev server? If so, that's expected. You should see the info only if you build the project and deploy it to CF. |
So does this I'm also wondering if there is way to use CORS or someway to ensure that this API endpoint can only be run by my project and its domain? Really thanks for the help thus far! |
@kelvin-zhao yeah that code makes sense |
But how do you get rid of the typescript error? |
We are going to fix it in this PR: https://github.com/withastro/astro/pull/8190/files#diff-a74615b421da488d5e2bcf3e14c80732c192a374f51901a2064b3e2caef9d529 |
What version of
astro
are you using?Latest
Are you using an SSR adapter? If so, which one?
Cloudflare
What package manager are you using?
npm
What operating system are you using?
Mac,
What browser are you using?
Chrome
Describe the Bug
I have no access to environment variables via cloudflare, and I do override the connection string an a ts file and import it in a route
What's the expected result?
I should be able to access the old getRuntime() out of the new usage Astro.Locals.runtime
as I cannot access this in the .ts files
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-wj2hw8?file=src%2Fdb.ts
Participation
The text was updated successfully, but these errors were encountered: