Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion deploy/lib/multiscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ module.exports = {
const workerScriptResponse = await ms.deployWorker(this.provider.config.accountId, this.serverless, functionObject);
const routesResponse = await ms.deployRoutes(this.provider.config.zoneId, functionObject);

let zonelessResponse;

if (functionObject.zoneless) {
zonelessResponse = await ms.deployZoneless(this.provider.config.accountId, functionObject);
}

return {
workerScriptResponse,
routesResponse,
namespaceResponse
namespaceResponse,
zonelessResponse
};
});
},
Expand Down
3 changes: 2 additions & 1 deletion shared/accountType.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ const cf = require("cloudflare-workers-toolkit");

module.exports = {
async checkAccountType() {
const accountId = this.provider.config.accountId;
const zoneId = this.provider.config.zoneId;
return await BB.bind(this)
.then(this.checkAllEnvironmentVariables)
.then(function() {
return cf.workers.getSettings({zoneId});
return cf.workers.getSettings({zoneId, accountId});
})
.then(this.checkIfMultiScript)
},
Expand Down
15 changes: 14 additions & 1 deletion shared/duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ module.exports = {

const { zoneId } = provider.config;

const functions = serverless.service.getAllFunctions();

const hasRoutes = functions.some(scriptName => {
const functionObject = serverless.service.getFunction(scriptName);

if (functionObject.events && functionObject.events.length) {
return true;
}
});

if (!hasRoutes) {
return false;
}

if (!zoneId) {
throw("You must specify a Zone ID CLOUDFLARE_ZONE_ID");
}
Expand All @@ -43,7 +57,6 @@ module.exports = {
const foundDuplicate = result.some(filters => {
const { pattern, script } = filters;

const functions = serverless.service.getAllFunctions();
for (const scriptName of functions) {
const functionObject = serverless.service.getFunction(scriptName);
const routes = functionObject.events.map(function(event) {
Expand Down
14 changes: 14 additions & 0 deletions shared/multiscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const cf = require("cloudflare-workers-toolkit");
const sdk = require("../provider/sdk");
const path = require("path");
const { generateCode, generateWASM } = require("../deploy/lib/workerScript");

Expand Down Expand Up @@ -145,5 +146,18 @@ module.exports = {
}

return routeResponses;
},

async deployZoneless(accountId, functionObject) {
const name = functionObject.name;

const response = await sdk.cfApiCall({
url: `/accounts/${accountId}/workers/scripts/${name}/subdomain`,
method: `POST`,
contentType: 'application/json',
body: JSON.stringify({enabled: true})
});

return response;
}
}