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

Cloudflare Adapter Directory Mode not working as expected #6018

Closed
1 task
benadam11 opened this issue Jan 29, 2023 · 6 comments · Fixed by #6046
Closed
1 task

Cloudflare Adapter Directory Mode not working as expected #6018

benadam11 opened this issue Jan 29, 2023 · 6 comments · Fixed by #6046
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@benadam11
Copy link

What version of astro are you using?

2.0.2

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

Describe the Bug

Running astro build should bundle the API routes and create a functions directory with a file called [[path]].js. With version 6.1 a functions dir is created, but the [[path]].js file is not (instead it is creating a _worker.js file in dist).

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-xngtpq

Participation

  • I am willing to submit a pull request for this issue.
@benadam11
Copy link
Author

benadam11 commented Jan 29, 2023

There are several issues (but I believe this is the main one) ... The other issue with pre-rendering enabled is if your site has more than a few pages, your exclude in the _route.json will exceed Cloudflares routes limit (100) which causes a failure as well. Fortunately I can work around that by providing a custom _routes.json

@AirBorne04
Copy link
Contributor

Hi @benadam11 lets work through it 😄

what you described is correct, apparently there was a renaming of the serverEntry of the worker.js to worker.mjs @matthewp do you know why that was done during the streaming update here

For the routes, I implemented a simple algo which is just adding all files from the dist folder into the excludes section and for cases you mentioned only create one if not present. A more advanced approach could possibly create issues which are hard to anticipate. Maybe with the latest updates we can generally exclude the _astro folder instead of listing all files.

@matthewp
Copy link
Contributor

@AirBorne04 sorry about that, this is on my board to fix. If you have a quick fix feel free to submit a PR.

The reason why the extension was changed to .mjs was to support prerendering. In prerendering we need the entrypoint to be a .mjs file or Node will complain that it contains imports.

However, it gets renamed to _worker.js at the end of the build. So I'm not sure why people are seeing this issue yet.

@matthewp matthewp self-assigned this Jan 30, 2023
@matthewp matthewp added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Jan 30, 2023
@AirBorne04
Copy link
Contributor

ok, understood, no problem, I already found the cause I will send a PR

@matthewp
Copy link
Contributor

@AirBorne04 ok thank you! Will review your PR as soon as it lands as this is an urgent regression to fix.

I would put off the _astro change as I think it might need some discussion (for example, it's configuration so it's not guaranteed to be that name).

@matthewp
Copy link
Contributor

I see where the problem is too, working on fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants