| 9 | } |
| 10 | |
| 11 | _getCurrentProject(data, onProjectExists, onCreateProject) { |
| 12 | |
| 13 | const options = { |
| 14 | port: 443, |
| 15 | hostname: 'api.cloudflare.com', |
| 16 | path: `/client/v4/accounts/${this.v.get('CLOUDFLARE_ACCOUNT_ID')}/pages/projects/${this.v.get('CLOUDFLARE_PROJECT_NAME')}`, |
| 17 | headers: { |
| 18 | 'Authorization': `Bearer ${this.v.get('CLOUDFLARE_API_TOKEN')}`, |
| 19 | 'Content-Type': 'application/json', |
| 20 | }, |
| 21 | method: 'GET', |
| 22 | }; |
| 23 | |
| 24 | https.get(options, (res) => { |
| 25 | if (res.statusCode === 404) { |
| 26 | onCreateProject(); |
| 27 | return; |
| 28 | } |
| 29 | // console.log('headers:', res.headers); |
| 30 | |
| 31 | let body = ''; |
| 32 | res.on('data', (d) => { |
| 33 | body += d; |
| 34 | }); |
| 35 | res.on('end', function () { |
| 36 | try { |
| 37 | let json = JSON.parse(body); |
| 38 | onProjectExists(json); |
| 39 | } catch (error) { |
| 40 | console.error(error.message); |
| 41 | process.exit(1); |
| 42 | } |
| 43 | }); |
| 44 | }).on('error', (e) => { |
| 45 | console.error(e); |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | _createProject(data, onSuccess) { |
| 50 | const options = { |