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

astrojs/db doesn't work on cloudflare pages #12019

Open
1 task
zeshhaan opened this issue Sep 18, 2024 · 6 comments
Open
1 task

astrojs/db doesn't work on cloudflare pages #12019

zeshhaan opened this issue Sep 18, 2024 · 6 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority) pkg: db

Comments

@zeshhaan
Copy link

zeshhaan commented Sep 18, 2024

Astro Info

$ astro info
Astro                    v5.0.0-beta.1
Node                     v20.10.0
System                   macOS (arm64)
Package Manager          bun
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/react
                         @astrojs/tailwind
                         astro:db

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

@astrojs/db when used with libsql credentials doesn't work on cloudflare pages. it works fine on local but when accessing a page with astro db query on preview/production env, it breaks with 500. The console gives the following error message:
LibsqlError: SERVER_ERROR: Server returned HTTP status 401

What's the expected result?

When interacting with Astro DB using libsql credentials in a Cloudflare deployed site, say for example, querying a db, we're expected to see it return a result. But instead, it breaks and returns 500 error.

Link to Minimal Reproducible Example

https://github.com/zeshhaan/error-astrodb-cf-repro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 18, 2024
@zeshhaan zeshhaan changed the title astrojs/db with libsql connection fails on production astrojs/db doesn't work on cloudflare pages Sep 18, 2024
@Fryuni Fryuni added - P2: nice to have Not breaking anything but nice to have (priority) pkg: db and removed needs triage Issue needs to be triaged labels Sep 19, 2024
@atej
Copy link

atej commented Sep 26, 2024

Running into the same issue trying to use astro-db with Turso on a Cloudflare Pages deployment.

@ematipico
Copy link
Member

Is anyone able to provide better logs here?

@zeshhaan
Copy link
Author

zeshhaan commented Oct 7, 2024

Is anyone able to provide better logs here?

there was a discussion in a related thread on discord with folks sharing the logs (if that might help)
https://discord.com/channels/830184174198718474/1285132367929020416

@misaelvillaverde
Copy link

Same issue, I'm getting:

{
    "code": "SERVER_ERROR",
    "name": "LibsqlError"
}

Works fine locally (and astro dev --remote). Don't work when on cloudflare workers environment, i.e. wrangler dev or deployed to cloudflare pages. Also, compatibility_flags = ["nodejs_compat"], don't change anything. Can't get a meaningful error for the time being.

@nootsponge
Copy link

Hello! Looks like the issue is to do with how the database variable is instantiated. Stack traces aren't entirely useful since it's all compiled and random looking but through some thorough sniffing around I found out that:

  1. The parameters for remoteUrl and appToken are being assigned to variables that do not exist; and
  2. Workers use a passed variable in the fetch() function to give the application its correct environment, NOT process.env like you would assume.

image

So, in summary, Workers only exposes environment variables per fetch() as the passed env parameter, which I cannot find how to access via the generated page module.

I'd love to contribute to fix this if anyone can point me in the right direction.

@nathanpower
Copy link

I'd love to contribute to fix this if anyone can point me in the right direction.

Not sure about the worker runtime, but I just hit a similar issue because I was on Node 20 and support for .env loading is experimental. I had to run with node --env-file=.env ./dist/server/entry.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) pkg: db
Projects
None yet
Development

No branches or pull requests

7 participants