Comments (3)
this was a bug in our handling of the types being passed through. this is now resolved in v3.0.0-beta.8
working example
import Cloudflare from "cloudflare";
const cf = new Cloudflare({
apiToken: "<token>"
});
cf.workers.scripts.update("test-worker", {
"index.js": new File(
[
`export default {
async fetch() {
return new Response("Hello!");
}
}`,
],
"index.js",
{
type: "application/javascript+module",
}
),
metadata: new File(
[
JSON.stringify({
bindings: [],
main_module: "index.js",
}),
],
"metadata.json",
{
type: "application/json",
}
),
account_id: "<account id>",
});
from cloudflare-typescript.
your second example is how this should be done. here is my snippet using 3.0.0-beta.3:
import Cloudflare from "cloudflare";
const cf = new Cloudflare({
apiEmail: process.env["CLOUDFLARE_EMAIL"],
apiKey: process.env["CLOUDFLARE_API_KEY"],
});
cf.workers.scripts.update("test-typescript-worker", {
"index.mjs": new File(
[
`export default {
async fetch() {
return new Response("Hello!");
}
}`,
],
"index.mjs",
{
type: "application/javascript+module",
}
),
metadata: new File(
[
JSON.stringify({
bindings: [],
main_module: "index.mjs",
}),
],
null,
{
type: "application/json",
}
),
account_id: "f037e56e89293a057740de681ac9abbe",
});
unfortunately, the bit that isn't working is the content-type handling. here is an example of a working payload (from Go):
--f396ba51d2fc6a4a456bbf43a15e20534fcb5b145d69c2ead78b274bc40c
Content-Disposition: form-data; name="metadata"
Content-Type: application/json
{"main_module":"worker.mjs","bindings":[]}
--f396ba51d2fc6a4a456bbf43a15e20534fcb5b145d69c2ead78b274bc40c
Content-Disposition: form-data; name="worker.mjs"; filename="worker.mjs"
Content-Type: application/javascript+module
export default {
async fetch() {
return new Response("Hello!");
}
}
--f396ba51d2fc6a4a456bbf43a15e20534fcb5b145d69c2ead78b274bc40c--
note the content-types of application/json
and application/javascript+module
respectively.
however, when executing from the SDK, i can see that the content-types are not being picked up correctly. instead, they are defaulting to application/octet-stream
.
---WebkitFormBoundaryf1f6a8736e384264b6e541aad3605aaf
Content-Disposition: form-data; name="index.mjs"; filename="index.mjs"
Content-Type: application/octet-stream
export default {
async fetch() {
return new Response("Hello!");
}
}
---WebkitFormBoundaryf1f6a8736e384264b6e541aad3605aaf
Content-Disposition: form-data; name="metadata"
Content-Type: application/octet-stream
{"bindings":[],"main_module":"index.mjs"}
---WebkitFormBoundaryf1f6a8736e384264b6e541aad3605aaf--
this will need investigation as it looks like this either specific to the SDK or node. new File
within Workers seems to be doing the right thing.
from cloudflare-typescript.
@jacobbednarz Thanks
from cloudflare-typescript.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloudflare-typescript.