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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: Inconsistent behaviour in _routes.json. Also, no way to specify index file. #2046

Open
colecrouter opened this issue Oct 18, 2022 · 8 comments
Assignees
Labels
bug Something that isn't working pages:validated A validated Pages issue pages Relating to Pages

Comments

@colecrouter
Copy link
Contributor

What version of Wrangler are you using?

2.1.12

What operating system are you using?

Windows

Describe the Bug

When using a _routes.json, the following:

"include": [
    "/*"
],
"exclude": [
    "/"
]

鈥搑esults in all paths being excluded.

What I expected to happen was / (index.html) would be excluded, while everything else was included. I imagine this isn't intentional, as this sounds like what should happen if both include and exclude were set to /*, except that Wrangler won't let you do that.

That being said, I cannot find a way to reference a root level index file, as / doesn't work.

I tested this both on Wrangler and deployed; the behaviour is the same.

@colecrouter colecrouter added the bug Something that isn't working label Oct 18, 2022
@colecrouter colecrouter changed the title 馃悰 BUG: Inconsistent behaviour in _routes.json`. Also, no way to specify index file. 馃悰 BUG: Inconsistent behaviour in _routes.json. Also, no way to specify index file. Oct 19, 2022
@GregBrimble GregBrimble added the pages Relating to Pages label Oct 19, 2022
@GregBrimble
Copy link
Member

Thanks for the report. Sounds like a bug to me! cc'ing in the experts: @jahands and @CarmenPopoviciu

@nprogers nprogers added the pages:validated A validated Pages issue label Oct 19, 2022
@CarmenPopoviciu
Copy link
Contributor

CarmenPopoviciu commented Oct 19, 2022

@Mexican-Man thx so much for reporting this!

/ should indeed be the way to reference a root level index.

I tested this both on Wrangler and deployed

Can you please give me more details? Which wrangler commands did you try? What kind of project did you use for your test case - /functions or _worker.js? How did you deploy it?

I have tested (in MacOS) your _routes.json config in a Pages Functions project, by running:

  • wrangler pages dev [can confirm what you reported] NEEDS FIX
  • wrangler pages publish [works as expected]
  • git push to GH project [works as expected]

@colecrouter
Copy link
Contributor Author

colecrouter commented Oct 19, 2022

I was using a SvelteKit project (_worker.js) trying to work on another issue with SvelteKit, where I mentioned this issue in.
Here was my process:

  • Take the built file, add a console.log inside the exported fetch.
  • Modify _routes.json, load different pages/resources, see how many times console.log is called.
  • Confirmed the behaviour using wrangler pages dev

Of course I can't view logs once deployed, but when using wrangler pages publish, I noticed the same set of errors (in the browser) from adding and removing / from _routes.json. That being the case, I assumed that the same issue was present.

  • wrangler pages publish [works as expected]

@CarmenPopoviciu where you able to get / working when deployed?

EDIT: To clarify, the errors I get locally and remotely are 404 errors, implying the routes from the include rule are being overwritten by exclude.

@CarmenPopoviciu
Copy link
Contributor

@Mexican-Man thank you for all the details <3!

I've tested with a basic _worker.js project and I can still only confirm that wrangler pages dev is broken, but not wrangler pages publish. For your reference, you can find the test repo here: https://github.com/CarmenPopoviciu/pages-am. I'll have a stab at a SvelteKit project as well, but didn't get to it yet.

Is your project available somewhere for me to have a look? Or, compared to the test repo I mentioned above, is there anything in particular that stands out to you?

@CarmenPopoviciu
Copy link
Contributor

@Mexican-Man just FYI I pushed a fix for wrangler pages dev that should be available now if you update to latest wrangler version.

is wrangler pages publish still an issue for you?

@colecrouter
Copy link
Contributor Author

Is your project available somewhere for me to have a look? Or, compared to the test repo I mentioned above, is there anything in particular that stands out to you?

Sorry. I don't have it available right now, but I could potentially put something up.

Also @CarmenPopoviciu, testing with wrangler@latest, / no longer breaks 馃槉. However, neither / or /index.html seem to catch requests to http://127.0.0.1:8788/ (in my case).

@CarmenPopoviciu CarmenPopoviciu self-assigned this Mar 13, 2023
@syonfox
Copy link

syonfox commented Mar 1, 2024

Hi any update on this, Im trying to deploy pages but its not respectin my _routes.json in the root directory

{
  "version": 1,
  "include": [
    "/*"
  ],
  "exclude": [
    "/lib/*",
    "/*.html",
    "/index.html",
    "/css/*",
    "/js/*",
    "/fonts/*",
    "/data/*",
    "/music/*",
    "/libs/*",
    "/img/*",
    "/map42/*",
    "/plugins/*",
    "/pro/login3.html"
  ]
}

this file is generated where it removed directories until under the 99 limit theoretically there is a smarter way.

Anyway the problem is when i run the project
npx wrangler@ pages dev ./public --persist-to ./pages --ip 127.0.0.1 --port 8111 --kv kv --kv ski --log-level debug

it still runs my middleware for everything even my public assets which should be excluded

@syonfox
Copy link

syonfox commented Mar 1, 2024

It seams easy enoug to implement

If the exclueded files bypas midalware then should work as intnteded on dev and production

psudo code

let routes = require("./_routes.json")
cloudflarePagesbackend.server() {
  if(routes.excules.any(r=>matches(thisRequestUrl))) {
    fallThroughToStaticPublic
  }
  handle functions or
  fallThroughToStaticPublic
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working pages:validated A validated Pages issue pages Relating to Pages
Projects
None yet
Development

No branches or pull requests

5 participants