Closed APTy closed 3 years ago
@APTy - Hi, thanks for putting together a great report here. This is actually the expected behavior, and with a small tweak to your wrangler.toml
, you can achieve the outcome you're looking for:
- rules = [{type = "Data", globs = ["**/*.html"]}, {type = "Data", globs = ["**/*.js"]}]
+ rules = [{type = "Data", globs = ["**/*.html"], fallthrough = true}, {type = "Data", globs = ["**/*.js"]}]
adding fallthrough = true
to your Data module type rule will indicate that other matches can be considered, a la the docs:
fallthrough
(optional) This option allows further rules for this module type to be considered if set to true. If not specified or set to false, further rules for this module type will be ignored.
(search for "fallthrough" on this page: https://developers.cloudflare.com/workers/cli-wrangler/configuration)
Closing the issue, but please feel free to leave more comments / questions.
π Bug report
Describe the bug
Unexpected behavior serving javascript files using
build.upload.rules
when two entries of typeData
are supplied (one for**/*.html
and one for**/*.js
)Reproduce the bug
A list of steps to reproduce the bug.
git clone https://github.com/APTy/workers-chat-demo.git && cd workers-chat-demo
a. This is a fork of https://github.com/cloudflare/workers-chat-demo with an extra commit (https://github.com/APTy/workers-chat-demo/commit/f02308f9d617837f54ee2739dff1cdf96be9c2c1) on top.wrangler publish && wrangler dev
curl localhost:8787
Expected behavior
We expect to see the content of this file: https://github.com/APTy/workers-chat-demo/blob/master/src/foo.js being served:
What we see instead
What's peculiar is that
foo.js
is executed by the cloudflare worker.. The"test"
print statement shows up on the server's logs! π± This is mildly concerning because the docs say that the"Data"
type should only be serializing these files into anArrayBuffer
and not executing it.Environment and versions
Fill out the following information about your environment.
macOS 11.5.2
wrangler -V
:wrangler 1.19.5
node -v
:v12.16.3
wrangler.toml
: https://github.com/APTy/workers-chat-demo/blob/master/wrangler.toml[build.upload] format = "modules" dir = "src" main = "./chat.mjs"
[works] the following line correctly serves the javascript file
rules = [{type = "Data", globs = ["*/.js"]}]
[doesn't work] the following line does not serve the javascript file correctly
rules = [{type = "Data", globs = ["*/.html"]}, {type = "Data", globs = ["*/.js"]}]
[durable_objects] bindings = [ { name = "rooms", class_name = "ChatRoom" }, { name = "limiters", class_name = "RateLimiter" } ]
Indicate that you want the ChatRoom and RateLimiter classes to be callable as Durable Objects.
[[migrations]] tag = "v1" # Should be unique for each entry new_classes = ["ChatRoom", "RateLimiter"]