-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdeploy.js
36 lines (34 loc) · 1.04 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// adapted from https://github.com/cloudflare/workers-react-example/blob/master/scripts/deploy.js
require("dotenv").config({ path: ".env" });
const fs = require("fs");
const util = require("util");
const fetch = require("node-fetch");
const readFile = util.promisify(fs.readFile);
async function deploy(script) {
let resp = await fetch(
`https://api.cloudflare.com/client/v4/zones/${
process.env.ZONE_ID
}/workers/script`,
{
method: "PUT",
headers: {
"cache-control": "no-cache",
"content-type": "application/javascript",
"X-Auth-Email": process.env.ACCOUNT_EMAIL,
"X-Auth-Key": process.env.ACCOUNT_AUTH_KEY
},
body: script
}
);
let data = await resp.json();
return data;
}
readFile("dist/worker.js", "utf8").then(data => {
deploy(data).then(d => {
if (d.success) {
console.log("Worker uploaded");
} else {
console.log(d.errors);
}
});
});