cloudflare/ts/cloudflare.classes.workermanager.ts

32 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-07-18 09:51:56 +00:00
import * as plugins from './cloudflare.plugins';
import { CloudflareAccount } from './cloudflare.classes.account';
2019-07-18 12:25:10 +00:00
import { Worker } from './cloudflare.classes.worker';
2019-07-18 09:51:56 +00:00
export class WorkerManager {
2019-07-18 12:25:10 +00:00
private cfAccount: CloudflareAccount;
2019-07-18 09:51:56 +00:00
constructor(cfAccountArg: CloudflareAccount) {
this.cfAccount = cfAccountArg;
}
2019-07-18 12:25:10 +00:00
public async createWorker(workerName: string, workerScript: string): Promise<Worker> {
const accountIdentifier = await this.cfAccount.getAccountIdentifier();
const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`;
const responseBody = await this.cfAccount.request('PUT', route, workerScript, {
'Content-Type': 'application/javascript',
'Content-Length': Buffer.byteLength(workerScript)
});
return Worker.fromApiObject(this, responseBody);
}
/**
* lists workers
*/
public async listWorkers() {
const accountIdentifier = await this.cfAccount.getAccountIdentifier();
const route = `/accounts/${accountIdentifier}/workers/scripts`;
const response = await this.cfAccount.request('GET', route);
console.log(response);
}
2019-07-18 09:51:56 +00:00
}