diff --git a/docs/README.md b/docs/README.md index 3189bfba559..8b736e1a8ab 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,6 +13,7 @@ menuItems: - {menuText: "- Kubeless" , path: /framework/docs/providers/kubeless/} - {menuText: "- Spotinst" , path: /framework/docs/providers/spotinst/} - {menuText: "- Webtasks" , path: /framework/docs/providers/webtasks/} + - {menuText: "- Cloudflare" , path: /framework/docs/providers/cloudflare/} --> @@ -157,4 +158,19 @@ Already using AWS or another cloud provider? Read on. +
+
+ + + +
+
+ +
+
diff --git a/docs/providers/cloudflare/README.md b/docs/providers/cloudflare/README.md new file mode 100644 index 00000000000..5cdc8327304 --- /dev/null +++ b/docs/providers/cloudflare/README.md @@ -0,0 +1,71 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/) + + +# Cloudflare Provider Documentation + +Welcome to the Serverless Cloudflare Workers documentation! + +If you have any questions, [search the forums](https://forum.serverless.com?utm_source=framework-docs) or [start your own thread](https://forum.serverless.com?utm_source=framework-docs) + +
+
+
+ + Serverless Framework Cloudflare Workers Guide + +
+ +
+ +
+
+ + Serverless Framework Cloudflare Workers CLI Reference + +
+
+ +
+
+ +
+
+ + Serverless Framework Cloudflare Workers Events Reference + +
+
+ +
+
+
diff --git a/docs/providers/cloudflare/cli-reference/README.md b/docs/providers/cloudflare/cli-reference/README.md new file mode 100644 index 00000000000..5e37d803895 --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/README.md @@ -0,0 +1,15 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/) + + +# Serverless Cloudflare Workers CLI Reference + +Welcome to the Serverless Cloudflare Workers CLI Reference! Please select a section on the left to get started. + +If you have questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/). diff --git a/docs/providers/cloudflare/cli-reference/create.md b/docs/providers/cloudflare/cli-reference/create.md new file mode 100644 index 00000000000..e5ce773dbec --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/create.md @@ -0,0 +1,76 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/create) + + + +# Cloudflare Workers - Create +Creates a new Serverless service in the current working directory based on the provided template. + +**Create service in current working directory:** + +```bash +serverless create --template cloudflare-workers +``` + +Or for Enterprise Cloudflare accounts: + +```bash +serverless create --template cloudflare-workers-enterprise +``` + +**Create service in new folder:** + +```bash +serverless create --template cloudflare-workers --path my-service +``` + +Or for Enterprise Cloudflare accounts: + +```bash +serverless create --template cloudflare-workers-enterprise --path my-service +``` + +## Options +- `--template` or `-t` The name of one of the available templates. Required if --template-url and --template-path are not present. +- `--template-url` or `-u` The name of one of the available templates. Required if --template and --template-path are not present. +- `--template-path` The local path of your template. Required if --template and --template-url are not present. +- `--path` or `-p` The path where the service should be created. +- `--name` or `-n` the name of the service in `serverless.yml`. +## Provided lifecycle events +- `create:create` +## Available Templates for Cloudflare Workers +To see a list of available templates run `serverless create --help` +These are the current available templates for Cloudflare Workers: + +- cloudflare-workers +- cloudflare-workers-enterprise + +## Examples +### Creating a new service +```bash +serverless create --template cloudflare-workers --name my-special-service +``` + +This example will generate scaffolding for a service with `Cloudflare` as a provider. The scaffolding will be generated in the current working directory. + +### Creating a named service in a (new) directory +```bash +serverless create --template cloudflare-workers --path my-new-service +``` + +This example will generate scaffolding for a service with `Cloudflare` as a provider. The scaffolding will be generated in the `my-new-service` directory. This directory will be created if not present. Otherwise, Serverless will use the already present directory. +Additionally, Serverless will rename the service according to the path you provide. In this example, the service will be renamed to `my-new-service`. + +### Creating a new service using a local template +```bash +serverless create --template-path path/to/my/template/folder --path path/to/my/service --name my-new-service +``` +This will copy the `path/to/my/template/folder` folder into `path/to/my/service` and rename the service to `my-new-service`. diff --git a/docs/providers/cloudflare/cli-reference/deploy.md b/docs/providers/cloudflare/cli-reference/deploy.md new file mode 100644 index 00000000000..6e9c3e5fbe4 --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/deploy.md @@ -0,0 +1,50 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/deploy) + + + +# Cloudflare Workers - Deploy +In order to be able to deploy any Cloudflare Workers, You will need to set your Global API key from Cloudflare as an environmental variable named `CLOUDFLARE_AUTH_KEY`, and your Cloudflare account email as an environmental variable named `CLOUDFLARE_AUTH_EMAIL`. You can get your Global API key from your [Cloudflare profile](https://dash.cloudflare.com/profile) page. You will also need to set `accountId` and `zoneId` in `serverless.yml` under `service.config`. The first part of the path when you open [Cloudflare dashboard](https://dash.cloudflare.com/) as a logged in user is your `accountId`, e.g. `dash.cloudflare.com/{accountId}`. And the `zoneId` can be found from the overview tab after selecting the desired zone from the [Cloudflare dashboard](https://dash.cloudflare.com/). + +Environmental variables are variables that live inside your terminal. + +For Mac and Linux users, you can set environmental variables like this: + +```bash +export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +And for Windows (CMD) users, you can set environmental variables like this: + +```bash +set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +You’ll need to redefine your environmental variables after each time you close your terminal. + +The `serverless deploy` command deploys your entire service via the Cloudflare Workers API. Run this command when you have made service changes (i.e., you edited `serverless.yml`). +Use `serverless deploy -f my-function` when you have made code changes and you want to quickly upload your updated code to Cloudflare. + +```bash +serverless deploy +``` + +This is the simplest deployment usage possible. With this command, Serverless will deploy your service to Cloudflare. + +## Options +- `--verbose` or `-v`: Shows all stack events during deployment, and display any Stack Output. +- `--function` or `-f`: Invokes `deploy function` (see above). Convenience shortcut + +## Provided lifecycle events +- `deploy:deploy` +- `deploy:function:deploy` diff --git a/docs/providers/cloudflare/cli-reference/invoke.md b/docs/providers/cloudflare/cli-reference/invoke.md new file mode 100644 index 00000000000..a3bfdf030c6 --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/invoke.md @@ -0,0 +1,62 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/fn/cli-reference/invoke) + + +# Fn - Invoke + +Invokes deployed function. It allows to send event data to the function, read logs and display other important information of the function invocation. + +```bash +serverless invoke --function functionName +``` + +## Options +- `--function` or `-f` The name of the function in your service that you want to invoke. **Required**. +- `--data` or `-d` String data to be passed as an event to your function. By default data is read from standard input. +- `--path` or `-p` The path to a json file with input data to be passed to the invoked function. This path is relative to the root directory of the service. +- `--log` or `-l` If set to `true`, it will output logging data of the invocation. Default is `false`. + +## Provided lifecycle events +- `invoke:invoke` + +## Examples + +### Fn + +```bash +serverless invoke --function functionName +``` + +This example will invoke your deployed function on the configured Fn Api Url +endpoint. This will output the result of the invocation in your terminal. + +#### Function invocation with data + +```bash +serverless invoke --function functionName --data '{"name": "Bernie"}' +``` + +#### Function invocation with logging + +```bash +serverless invoke --function functionName --log +``` + +Just like the first example, but will also outputs logging information about your invocation. + +#### Function invocation with data passing + +```bash +serverless invoke --function functionName --path lib/data.json +``` + +This example will pass the json data in the `lib/data.json` file (relative to the root of the service) while invoking +the specified/deployed function. diff --git a/docs/providers/cloudflare/cli-reference/plugin-install.md b/docs/providers/cloudflare/cli-reference/plugin-install.md new file mode 100644 index 00000000000..0bb19f137f1 --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/plugin-install.md @@ -0,0 +1,42 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-install) + + +# Plugin Install + +Install a Serverless plugin and add it to the services `plugins` array. By default, a latest version is installed. +If you want a specific version, you can specify `@` as name option. + +**Note:** You might want to change the order of the plugin in the services `plugins` array. + +```bash +serverless plugin install --name pluginName +``` + +## Options +- `--name` or `-n` The plugins name. **Required**. + +## Provided lifecycle events +- `plugin:install:install` + +## Examples + +### Install the `serverless-webpack` plugin + +```bash +serverless plugin install --name serverless-webpack +``` + +### Install a specific version + +```bash +serverless plugin install --name serverless-webpack@3.0.0-rc.2 +``` diff --git a/docs/providers/cloudflare/cli-reference/plugin-list.md b/docs/providers/cloudflare/cli-reference/plugin-list.md new file mode 100644 index 00000000000..c7b74d80407 --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/plugin-list.md @@ -0,0 +1,25 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-list) + + +# Plugin List + +List all available plugins on the terminal. Connected to the [Serverless plugin registry](https://github.com/serverless/plugins). + +```bash +serverless plugin list +``` + +## Options +- *None* + +## Provided lifecycle events +- `plugin:list:list` diff --git a/docs/providers/cloudflare/cli-reference/plugin-search.md b/docs/providers/cloudflare/cli-reference/plugin-search.md new file mode 100644 index 00000000000..4f793f03511 --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/plugin-search.md @@ -0,0 +1,33 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-search) + + +# Plugin Search + +Search for a specific plugin based on a search query. Connected to the [Serverless plugin registry](https://github.com/serverless/plugins). + +```bash +serverless plugin search --query query +``` + +## Options +- `--query` or `-q` The query you want to use for your search. **Required**. + +## Provided lifecycle events +- `plugin:search:search` + +## Examples + +### Search for a `sqs` plugin + +```bash +serverless plugin search --query sqs +``` diff --git a/docs/providers/cloudflare/cli-reference/plugin-uninstall.md b/docs/providers/cloudflare/cli-reference/plugin-uninstall.md new file mode 100644 index 00000000000..74852fb6b6f --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/plugin-uninstall.md @@ -0,0 +1,33 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-uninstall) + + +# Plugin Uninstall + +Uninstall a Serverless plugin and remove it from the services `plugins` array. + +```bash +serverless plugin uninstall --name pluginName +``` + +## Options +- `--name` or `-n` The plugins name. **Required**. + +## Provided lifecycle events +- `plugin:uninstall:uninstall` + +## Examples + +### Remove the `serverless-webpack` plugin + +```bash +serverless plugin uninstall --name serverless-webpack +``` diff --git a/docs/providers/cloudflare/cli-reference/remove.md b/docs/providers/cloudflare/cli-reference/remove.md new file mode 100644 index 00000000000..505bc0df19a --- /dev/null +++ b/docs/providers/cloudflare/cli-reference/remove.md @@ -0,0 +1,21 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/remove) + + +# Cloudflare Workers - Remove +The `serverless remove` command will remove the deployed service, defined in your current working directory, from the provider. + +```bash +serverless remove +``` +It will remove the Cloudflare Worker functions from the Cloudflare. +## Provided lifecycle events +- `remove:remove` diff --git a/docs/providers/cloudflare/events/README.md b/docs/providers/cloudflare/events/README.md new file mode 100644 index 00000000000..09b25c7a898 --- /dev/null +++ b/docs/providers/cloudflare/events/README.md @@ -0,0 +1,18 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/events/) + + +# Serverless Cloudflare Workers Events + +Welcome to the Serverless Cloudflare Workers Events Glossary! + +Please select a section on the left to get started. + +If you have questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/) + diff --git a/docs/providers/cloudflare/events/http.md b/docs/providers/cloudflare/events/http.md new file mode 100644 index 00000000000..0713feeae53 --- /dev/null +++ b/docs/providers/cloudflare/events/http.md @@ -0,0 +1,37 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/events/http) + + + +# Cloudflare Workers - HTTP Events +The only type of event that is supported in Cloudflare Workers is HTTP events, so defining events in your `serverless.yml` is optional. Defined events in your `serverless.yml` are only used by the `serverless invoke` command, which can be useful for testing your Functions. + +## Serverless Yml +When creating a service your serverless yml will define which endpoint is used for your function when you run the [`serverless invoke`](../cli-reference/invoke.md) command. + +```yml +# serverless.yml +... +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + events: + - http: + url: example.com/hello/user + method: GET + headers: + greeting: hi +``` + +The events section in the yml above makes it so that the Function helloWorld will be used for request to the `example.com/hello/user` endpoint. This configuration would send a GET request with a header called `greeting` that has a value of `hi` to the `example.com/hello/user` endpoint when you run `serverless invoke -f helloWorld`. \ No newline at end of file diff --git a/docs/providers/cloudflare/guide/README.md b/docs/providers/cloudflare/guide/README.md new file mode 100644 index 00000000000..bf10653c8fd --- /dev/null +++ b/docs/providers/cloudflare/guide/README.md @@ -0,0 +1,17 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/) + + +# Serverless Cloudflare Workers Guide + +Welcome to the Serverless Cloudflare Workers Guide! + +Get started with the **[Introduction to the Serverless framework](./intro.md)** + +If you have questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/) diff --git a/docs/providers/cloudflare/guide/debugging.md b/docs/providers/cloudflare/guide/debugging.md new file mode 100644 index 00000000000..d696b1932ab --- /dev/null +++ b/docs/providers/cloudflare/guide/debugging.md @@ -0,0 +1,62 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/debugging) + + +# Cloudflare Workers - Debugging +How can we debug errors in our Cloudflare Workers functions? + +Let's imagine that we have deployed the following code as a Cloudflare Worker function using Serverless: + +```javascript +addEventListener('fetch', event => { + event.respondWith(handleRequest(event.request)) + }) + async function handleRequest(request) { + const answer = request.headers.get("greeting") || "hello" + return new Response(answer + " world") + } + +``` +And its corresponding Serverless yml file: + +```yml +# serverless.yml +... +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + events: + - http: + url: example.com/hello/user + # Defines the method used by serverless when the `invoke` command is used. Cloudflare Workers only support GET requests for now + method: GET + headers: + greeting: hi +``` + +Let's invoke correctly that function + +```bash +serverless invoke --function helloWorld + +# Output +hi world +``` + + +If we were to call the above function without any headers, you would get `hello world` back instead of `hi world`, so we know that our worker is properly reading the greeting header. + +## Cloudflare Workers Playground + +Cloudflare Workers also have a [Playground](https://cloudflareworkers.com/#) you can use to modify a Cloudflare Worker and see the results live on the same screen. The Cloudflare Workers Playground is another great way to debug your worker. diff --git a/docs/providers/cloudflare/guide/deploying.md b/docs/providers/cloudflare/guide/deploying.md new file mode 100644 index 00000000000..74f8632d7bb --- /dev/null +++ b/docs/providers/cloudflare/guide/deploying.md @@ -0,0 +1,115 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/deploying) + + +# Cloudflare Workers - Deploying +The Serverless Framework was designed to provision your Cloudflare Workers Functions and Events. It does this via a couple of methods designed for different types of deployments. + +## prerequisites + +In order to deploy your Cloudflare Worker, you need to set your Cloudflare email as an environmental variable called `CLOUDFLARE_AUTH_EMAIL`, and your Cloudflare Global API Key as an environmental variable called `CLOUDFLARE_AUTH_KEY`. You will also need to set `accountId` and `zoneId` in `serverless.yml` under `service.config`. The first part of the path when you open [Cloudflare dashboard](https://dash.cloudflare.com/) as a logged in user is your `accountId`, e.g. `dash.cloudflare.com/{accountId}`. And the `zoneId` can be found from the overview tab after selecting the desired zone from the [Cloudflare dashboard](https://dash.cloudflare.com/). + +Environmental variables are variables that live inside your terminal. + +For Mac and Linux users, you can set environmental variables like this: + +```bash +export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +And for Windows (CMD) users, you can set environmental variables like this: + +```bash +set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +You’ll need to redefine your environmental variables after each time you close your terminal. + + + +## Deploy All +This is the main method for doing deployments with the Serverless Framework: + +```bash +serverless deploy +``` + +Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Cloudflare Worker. If you've made changes to any of your routes since last deploying, the Serverless Framework will update them on the server for you. + +### How It Works +The Serverless Framework reads in `serverless.yml` and uses it to provision your Functions. + +For each defined Function in your `serverless.yml` file, the Framework will create a Cloudflare Workers script. This means that only enterprise customers can declare more than one Function, but anyone can use [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/) to package their application into a single script. + +For example, let's take the following example `serverless.yml` file: + +```yml +# serverless.yml + +service: + name: hello-world + config: + accountId: CLOUDFLARE_ACCOUNT_ID + zoneId: CLOUDFLARE_ZONE_ID + workers: + hello: + routes: + - example.com/hello/* + foo_script: + routes: + - example.com/foo/* + +provider: + name: cloudflare + +plugins: + - serverless-cloudflare-workers + +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + # Events are optional to declare and only affect the `serverless invoke` command + events: + - http: + url: example.com/hello/user + method: GET + headers: + greeting: hi + + + # Only Enterprise accounts would be allowed to add this second function + foo: + worker: foo_script + script: bar + events: + - http: + url: example.com/foo/bar + method: GET +``` + +After deploying that file, you’ll be able to hit the specified top-level routes of your zone, `example.com/hello/*` and `example.com/foo/*`, and any endpoints that resolve to these routes, like `example.com/hello/user` and `example.com/foo/bar`. + +## Deploy Function +This deployment method updates or deploys a single function. It performs the platform API call to deploy your package without the other resources. It is much faster than re-deploying your whole service each time. + +```bash +serverless deploy --function myFunction +``` + +If you've made changes to the routes corresponding to this Function since last deploying, the Serverless Framework will update them on the server for you. + +### Tips +Check out the [deploy command docs](../cli-reference/deploy.md) for all details and options. diff --git a/docs/providers/cloudflare/guide/events.md b/docs/providers/cloudflare/guide/events.md new file mode 100644 index 00000000000..fb1228b6e80 --- /dev/null +++ b/docs/providers/cloudflare/guide/events.md @@ -0,0 +1,39 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/events) + + + +# Cloudflare Workers - Events +Simply put, events are the things that trigger your functions to run. Currently, they are optional to define and are only used by the `serverless invoke` command, which can be useful for testing your Functions. + +If you are using Cloudflare Workers as your provider, all `events` in the service are HTTP Events, because that is the only event that Cloudflare Workers currently support. + +```yml +# serverless.yml +… + +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + events: + - http: + url: example.com/hello/user + method: GET + headers: + greeting: hi +``` + +Then [`serverless invoke -f helloWorld`](../cli-reference/invoke.md) will make a GET request to `example.com/hello/user` with a header called `greeting` that has a value of `hi`. + +[View the Cloudflare Workers events section for more information on HTTP events](../events). diff --git a/docs/providers/cloudflare/guide/functions.md b/docs/providers/cloudflare/guide/functions.md new file mode 100644 index 00000000000..ab114991fea --- /dev/null +++ b/docs/providers/cloudflare/guide/functions.md @@ -0,0 +1,119 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/functions) + + +# Cloudflare Workers - Functions + +If you are using Cloudflare as a provider, all *functions* inside the service are Cloudflare Workers. + +## Configuration + +All of the Cloudflare Workers in your serverless service can be found in `serverless.yml` under the `functions` property. + +```yml +# serverless.yml + +service: + name: hello-world + config: + accountId: CLOUDFLARE_ACCOUNT_ID + zoneId: CLOUDFLARE_ZONE_ID + workers: + hello: + routes: + - example.com/hello/* + +provider: + name: cloudflare + +plugins: + - serverless-cloudflare-workers + +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + # Events are only relevant to the `serverless invoke` command and don’t affect deployment in any way + events: + - http: + url: example.com/hello/user + method: GET + headers: + someKey: someValue +``` + +The `script` property points to the file containing your Cloudflare Worker. + +```javascript +// helloWorld.js + +addEventListener('fetch', event => { + event.respondWith(handleRequest(event.request)) + }) + + async function handleRequest(request) { + return new Response("Hello world") + } +``` + +If you have an Enterprise Cloudflare account, you can add multiple Cloudflare Workers to your project. + +```yml +# serverless.yml + +service: + name: hello-world + config: + accountId: CLOUDFLARE_ACCOUNT_ID + zoneId: CLOUDFLARE_ZONE_ID + workers: + hello: + routes: + - example.com/hello/* + foo_script: + routes: + - example.com/foo/* + +provider: + name: cloudflare + +plugins: + - serverless-cloudflare-workers + +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + # Events are only relevant to the `serverless invoke` command and don’t affect deployment in any way + events: + - http: + url: example.com/hello/user + method: GET + headers: + someKey: someValue + + + # Only Enterprise accounts would be allowed to add this second function and its corresponding route above + foo: + worker: foo_script + script: bar + events: + - http: + url: example.com/foo/bar + method: GET +``` +The `script` property is what the Cloudflare Worker will be called on Cloudflare’s data centers. + +The `events` property is optional and is only relevant for using the `serverless invoke` command. Check out the [`events`](./events.md) guide for more information. diff --git a/docs/providers/cloudflare/guide/installation.md b/docs/providers/cloudflare/guide/installation.md new file mode 100644 index 00000000000..1771fcf70b1 --- /dev/null +++ b/docs/providers/cloudflare/guide/installation.md @@ -0,0 +1,57 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/installation) + + +# Cloudflare Workers - Installation + +## Installing Cloudflare Workers +Cloudflare Workers don’t actually require any installation to run. However, You will need to set your Global API key from Cloudflare as an environmental variable named `CLOUDFLARE_AUTH_KEY`, and your Cloudflare account email as an environmental variable named `CLOUDFLARE_AUTH_EMAIL`. You can get your Global API key from your [Cloudflare profile](https://dash.cloudflare.com/profile) page. + +Environmental variables are variables that live inside your terminal. + +For Mac and Linux users, you can set environmental variables like this: + +```bash +export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +And for Windows (CMD) users, you can set environmental variables like this: + +```bash +set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +You’ll need to redefine your environmental variables after each time you close your terminal. + +## Installing the Serverless Framework +Next, install the Serverless Framework via [npm](https://npmjs.org) which was already installed when you installed Node.js. + +Open up a terminal and type `npm install -g serverless` to install Serverless. + +```bash +npm install -g serverless +``` + +Once the installation process is done you can verify that Serverless is installed successfully by running the following command in your terminal: + +```bash +serverless +``` + +To see which version of serverless you have installed run: + +```bash +serverless --version +``` + +Remember, you need at least version 1.31.0 to use Cloudflare Workers with Serverless. diff --git a/docs/providers/cloudflare/guide/intro.md b/docs/providers/cloudflare/guide/intro.md new file mode 100644 index 00000000000..42c1c9bcd58 --- /dev/null +++ b/docs/providers/cloudflare/guide/intro.md @@ -0,0 +1,108 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/intro) + + + +# Cloudflare Workers - Introduction + +The Serverless Framework helps you develop and deploy serverless applications using [Cloudflare Workers](https://www.cloudflare.com/products/cloudflare-workers/). It's a CLI that offers structure, automation, and best practices out-of-the-box, allowing you to focus on building sophisticated, event-driven, serverless architectures, comprised of [Functions](#functions) and [Events](#events). It lets you manage your Worker routing in a flat configuration file that you can keep in alongside the rest of your code in version control, and the Serverless Framework will intelligently manage your routes as they change. + +The Serverless Framework is different than other application frameworks because: +* It manages your code as well as your infrastructure +* It supports multiple languages (Although Cloudflare Workers only supports Javascript for now) + +## Core Concepts +Here are the Serverless Framework's main concepts and how they pertain to Cloudflare Workers. + +### Functions +A Function is a Cloudflare Worker. It's an independent unit of deployment, like a microservice. It's merely code, deployed on Cloudflare’s 152+ PoPs (points of presence), that is most often written to perform a single job, such as: +* *Performing A/B Testing* +* *Custom routing based on user location, custom headers, etc.* +* *Hosting webhook endpoints* + +### Events +Anything that triggers a Cloudflare Worker Event to execute is regarded by the Framework as an **Event**. The only event that triggers a Cloudflare Worker is an HTTP request. Since the only event that can trigger a Worker is an HTTP request, declaring events is optional, and only used to declare specific endpoints that can be called by [`serverless invoke`](../cli-reference/invoke.md). This is useful for defining specific hooks into your application for testing. + +### Services +A **Service** is the Serverless Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions and the routes they will live on, all in one file entitled `serverless.yml`. Non-Enterprise Cloudflare accounts can only deploy one function (that can be deployed to multiple routes), while Enterprise Cloudflare accounts can deploy multiple functions at once: + +```yml +# serverless.yml + +service: + name: hello-world + config: + accountId: CLOUDFLARE_ACCOUNT_ID + zoneId: CLOUDFLARE_ZONE_ID + workers: + hello: + routes: + - example.com/hello/* + foo_script: + routes: + - example.com/foo/* + +provider: + name: cloudflare + +plugins: + - serverless-cloudflare-workers + +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + # Events are only relevant to the `serverless invoke` command and don’t affect deployment in any way + events: + - http: + url: example.com/hello/user + method: GET + headers: + someKey: someValue + + + # Only Enterprise accounts would be allowed to add this second function and its corresponding route above + foo: + worker: foo_script + script: bar + events: + - http: + url: example.com/foo/bar + method: GET +``` + +You get your `accountId` by grabbing it from the URL when using the [Cloudflare dashboard](https://dash.cloudflare.com), and your `zoneId` from the `overview` tab after selecting the desired zone from the [Cloudflare dashboard](https://dash.cloudflare.com). + +You will also need to set your Global API key from Cloudflare as an environmental variable named `CLOUDFLARE_AUTH_KEY`, and your Cloudflare account email as an environmental variable named `CLOUDFLARE_AUTH_EMAIL`. You can get your Global API key from your [Cloudflare profile](https://dash.cloudflare.com/profile) page. + +Environmental variables are variables that live inside your terminal. + +For Mac and Linux users, you can set environmental variables like this: + +```bash +export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +And for Windows (CMD) users, you can set environmental variables like this: + +```bash +set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +You’ll need to redefine your environmental variables after each time you close your terminal. + +If you’re not an enterprise customer and you want to execute different code on multiple routes with only one funciton, we recommend writing code based off of our [conditional routing](https://developers.cloudflare.com/workers/recipes/conditional-routing/) template to check your route and execute different code accordingly. You can also write workers in separate files and compile it into one worker with [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/). + +When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` is deployed at once. diff --git a/docs/providers/cloudflare/guide/quick-start.md b/docs/providers/cloudflare/guide/quick-start.md new file mode 100644 index 00000000000..c56c1311e46 --- /dev/null +++ b/docs/providers/cloudflare/guide/quick-start.md @@ -0,0 +1,105 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/quick-start) + + +# Cloudflare Workers - Quickstart + +## Pre-requisites +Node.js `v6.5.0` or later. +Serverless CLI `v1.31.0` or later. You can run `npm install -g serverless` to install it. + +## Create a new service +Create a new service using either the `cloudflare-workers` or `cloudflare-workers-enterprise` template, depending on your Cloudflare domain’s plan level, and specifying a unique name and an optional path for your service. + +```bash +# Create a new Serverless Service/Project +$ serverless create --template cloudflare-workers --path new-project +# Change into the newly created directory +$ cd new-project +# Install npm dependencies +$ npm install +``` + +Note: there are two templates for [Cloudflare Workers](https://www.cloudflare.com/products/cloudflare-workers/): `cloudflare-workers` and `cloudflare-workers-enterprise`. The enterprise template sets up a project that can natively deploy [multiple scripts](https://developers.cloudflare.com/workers/api/config-api-for-enterprise/), each with their own routes. It requires an enterprise Cloudflare account to use. + +The `cloudflare-workers` template still supports [conditional routing](https://developers.cloudflare.com/workers/recipes/conditional-routing/) and multiple scripts if you use a tool like [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/). + +## Deploy, test and diagnose your service + +You will need to set your Global API key from Cloudflare as an environmental variable named `CLOUDFLARE_AUTH_KEY`, and your Cloudflare account email as an environmental variable named `CLOUDFLARE_AUTH_EMAIL`. You can get your Global API key from your [Cloudflare profile](https://dash.cloudflare.com/profile) page. You will also need to set `accountId` and `zoneId` in `serverless.yml` under `service.config`. The first part of the path when you open [Cloudflare dashboard](https://dash.cloudflare.com/) as a logged in user is your `accountId`, e.g. `dash.cloudflare.com/{accountId}`. And the `zoneId` can be found from the overview tab after selecting the desired zone from the [Cloudflare dashboard](https://dash.cloudflare.com/). + +Environmental variables are variables that live inside your terminal. + +For Mac and Linux users, you can set environmental variables like this: + +```bash +export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +And for Windows (CMD) users, you can set environmental variables like this: + +```bash +set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE +set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL +``` + +You’ll need to redefine your environmental variables after each time you close your terminal. + +1. **Deploy the Service** + +Use this when you have made changes to your Functions, Events or Resources in `serverless.yml` or you simply want to deploy all changes within your Service at the same time. If you've made changes to your routes since last deploying, the Serverless Framework will update them on the server for you. + +```bash +serverless deploy +``` + +1. **Deploy the Function** + +Use this to quickly upload and overwrite your function code, allowing you to develop faster. + +```bash +serverless deploy -f hello +``` + +3. **Invoke the Function** + +Invokes the Function and returns results. + +```bash +serverless invoke --function helloWorld + +Hello world +``` + +Note that for `invoke`, your Function must have the `events` field populated in order for the `serverless` tool to know exactly which route to request. Defining the `headers` field is optional. + +```yml +# serverless.yml +... +foo: + worker: foo_script + script: bar + events: + - http: + url: example.com/foo/bar + method: GET + headers: + someKey: someValue +``` + + +## Cleanup +If at any point, you no longer need your service, you can run the following command to remove the Functions, Events and Resources that were created. + +```bash +serverless remove +``` diff --git a/docs/providers/cloudflare/guide/services.md b/docs/providers/cloudflare/guide/services.md new file mode 100644 index 00000000000..fdd2be9dae0 --- /dev/null +++ b/docs/providers/cloudflare/guide/services.md @@ -0,0 +1,202 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/services) + + +# Cloudflare Workers - Services + +A `service` is like a project. It's where you define your Cloudflare Workers and the `events` you test them with, all in a file called `serverless.yml`. + +To get started building your first Serverless Framework project, create a `service`. + +## Organization + +In the beginning of an application created by a team with an Enterprise Cloudflare account, and for the lifespan of an application made by a team with a Non-Enterprise Cloudflare account, we recommend you use a single Service to define all of the Functions and Events for that project. + +```bash +myService/ + serverless.yml # Contains all functions and infrastructure resources +``` + +However, as your application grows as an Enterprise Cloudflare user, you can break it out into multiple services. A lot of people organize their services by workflows or data models, and group the functions related to those workflows and data models together in the service. + +```bash +users/ + serverless.yml # Contains 4 functions that do Users CRUD operations and the Users database +posts/ + serverless.yml # Contains 4 functions that do Posts CRUD operations and the Posts database +comments/ + serverless.yml # Contains 4 functions that do Comments CRUD operations and the Comments database +``` + +This makes sense since related functions usually use common infrastructure resources, and you want to keep those functions and resources together as a single unit of deployment, for better organization and separation of concerns. + +## Creation + +To create a service, use the `create` command. You can also pass in a path to create a directory and auto-name your service: + +```bash +# Create service with cloudflare-workers template in the folder ./my-service +serverless create --template cloudflare-workers --path my-service +``` + +Here are the available runtimes for Cloudflare Workers: + +* cloudflare-workers +* cloudflare-workers-enterprise + +Check out the [create command docs](../cli-reference/create) for all the details and options. + +## Contents + +You'll see the following files in your working directory: + +- `serverless.yml` +- `helloWorld.js` + +### serverless.yml + +Each `service` configuration is managed in the `serverless.yml` file. The main responsibilities of this file are: + +- Declare a Serverless service +- Define one or more functions in the service + - Define the provider the service will be deployed to + - Define any custom plugins to be used + - Define events that trigger each function to execute (e.g. HTTP requests) + - Allow events listed in the `events` section to automatically create the resources required for the `serverless invoke` command + +You can see the name of the service, the provider configuration and the first function inside the `functions` definition. Any further service configuration will be done in this file. + +```yml +# serverless.yml + +service: + name: hello-world + config: + accountId: CLOUDFLARE_ACCOUNT_ID + zoneId: CLOUDFLARE_ZONE_ID + workers: + hello: + routes: + - example.com/hello/* + foo_script: + routes: + - example.com/foo/* + +provider: + name: cloudflare + +plugins: + - serverless-cloudflare-workers + +functions: + helloWorld: + # What the script will be called on Cloudflare + worker: hello + # The name of the script on your machine, omitting the .js file extension + script: helloWorld + # Events are only relevant to the `serverless invoke` command and don’t affect deployment in any way + events: + - http: + url: example.com/hello/user + method: GET + headers: + someKey: someValue + + + # Only Enterprise accounts would be allowed to add this second function and its corresponding route above + foo: + worker: foo_script + script: bar + events: + - http: + url: example.com/foo/bar + method: GET + +``` + +### helloWorld.js + +The `helloWorld.js` file contains a barebones Cloudflare Worker that returns ‘hello world’. + +## Deployment + +When you deploy a Service, all of the Functions, and Events in your `serverless.yml` are translated into calls to Cloudflare to create your Cloudflare Worker(s). + +To deploy a service, first `cd` into the relevant service directory: + +```bash +cd my-service +``` + +Then use the `deploy` command: + +```bash +serverless deploy +``` + +Check out the [deployment guide](./deploying.md) to learn more about deployments and how they work. Or, check out the [deploy command docs](../cli-reference/deploy.md) for all the details and options. + +## Removal + +To easily remove your Service from Cloudflare’s data centers, you can use the `remove` command. + +Run `serverless remove` to trigger the removal process. + +Serverless will start the removal and informs you about it's process on the console. A success message is printed once the whole service is removed. + +The removal process will only remove the service on your provider's infrastructure. The service directory will still remain on your local machine so you can still modify and (re)deploy it to another stage, region or provider later on. + +## Version Pinning + +The Serverless framework is usually installed globally via `npm install -g serverless`. This way you have the Serverless CLI available for all your services. + +Installing tools globally has the downside that the version can't be pinned inside package.json. This can lead to issues if you upgrade Serverless, but your colleagues or CI system don't. You can use a feature in your serverless.yml without worrying that your CI system will deploy with an old version of Serverless. + +### Pinning a Version + +To configure version pinning define a `frameworkVersion` property in your serverless.yaml. Whenever you run a Serverless command from the CLI it checks if your current Serverless version is matching the `frameworkVersion` range. The CLI uses [Semantic Versioning](http://semver.org/) so you can pin it to an exact version or provide a range. In general we recommend to pin to an exact version to ensure everybody in your team has the exact same setup and no unexpected problems happen. + +### Examples + +#### Exact Version + +```yml +# serverless.yml + +frameworkVersion: "=1.0.3" +``` + +#### Version Range + +```yml +# serverless.yml + +frameworkVersion: ">=1.0.0 <2.0.0" +``` + + +## Installing Serverless in an existing service + +If you already have a Serverless service, and would prefer to lock down the framework version using `package.json`, then you can install Serverless as follows: + +```bash +# from within a service +npm install serverless --save-dev +``` + +### Invoking Serverless locally + +To execute the locally installed Serverless executable you have to reference the binary out of the node modules directory. + +Example: +``` +node ./node_modules/serverless/bin/serverless deploy +``` diff --git a/docs/providers/cloudflare/guide/workflow.md b/docs/providers/cloudflare/guide/workflow.md new file mode 100644 index 00000000000..c6dda1f8d74 --- /dev/null +++ b/docs/providers/cloudflare/guide/workflow.md @@ -0,0 +1,58 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/workflow) + + + +# Cloudflare Workers - Workflow +Generally, Cloudflare Workers can be written locally, deployed with serverless, and tested with the [`serverless invoke`](../cli-reference/invoke.md) command. However, using the [Cloudflare Workers Playground](https://cloudflareworkers.com/#) can help you test and view your worker’s results live if you need more insight while developing your Cloudflare Worker. + +Below is a list of general tips for developing Cloudflare Workers with Serverless. + +### Development Workflow +Write your functions +Use `serverless deploy` only when you've made changes to `serverless.yml` and in CI/CD systems. +Use `serverless deploy -f myFunction` to rapidly deploy changes when you are working on a specific Cloudflare Workers Function. +Use `serverless invoke -f myFunction` to test your Cloudflare Workers Functions. +### Larger Projects +* For Non-Enterprise Cloudflare customers, combining multiple workers into one file or using [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/). +* Keep the Functions and Resources in your Serverless Services to a minimum. +## Cheat Sheet +A handy list of commands to use when developing with the Serverless Framework. + +##### Create A Service: +Creates a new Service: + +```bash +serverless create -p [SERVICE NAME] -t cloudflare-workers +``` + +##### Deploy All +Use this when you have made changes to your Functions, Events or Resources in `serverless.yml` or you simply want to deploy all changes within your Service at the same time. + +```bash +serverless deploy +``` + + +##### Deploy Function +Use this to quickly overwrite your Cloudflare Workers Functions, allowing you to develop faster if you have an Enterprise account that supports deploying multiple functions. + +```bash +serverless deploy -f [FUNCTION NAME] +``` + + +##### Invoke Function +Invokes a Cloudflare Workers Function. + +```bash +serverless invoke -f [FUNCTION NAME] +``` diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index d873426a76d..aa8cc06311d 100644 --- a/lib/plugins/create/create.js +++ b/lib/plugins/create/create.js @@ -34,6 +34,8 @@ const validTemplates = [ 'aws-go', 'aws-go-dep', 'azure-nodejs', + 'cloudflare-workers', + 'cloudflare-workers-enterprise', 'fn-nodejs', 'fn-go', 'google-nodejs', diff --git a/lib/plugins/create/templates/cloudflare-workers-enterprise/.gitignore b/lib/plugins/create/templates/cloudflare-workers-enterprise/.gitignore new file mode 100644 index 00000000000..9e5bccff87d --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers-enterprise/.gitignore @@ -0,0 +1,3 @@ +# Serverless directories +.serverless +node_modules/ diff --git a/lib/plugins/create/templates/cloudflare-workers-enterprise/bar.js b/lib/plugins/create/templates/cloudflare-workers-enterprise/bar.js new file mode 100644 index 00000000000..14359baeab9 --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers-enterprise/bar.js @@ -0,0 +1,7 @@ +addEventListener('fetch', event => { + event.respondWith(handleRequest(event.request)) + }) + + async function handleRequest(request) { + return new Response("Foo is not Bar") + } diff --git a/lib/plugins/create/templates/cloudflare-workers-enterprise/helloWorld.js b/lib/plugins/create/templates/cloudflare-workers-enterprise/helloWorld.js new file mode 100644 index 00000000000..dbede8a6255 --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers-enterprise/helloWorld.js @@ -0,0 +1,7 @@ +addEventListener('fetch', event => { + event.respondWith(handleRequest(event.request)) + }) + + async function handleRequest(request) { + return new Response("Hello world") + } diff --git a/lib/plugins/create/templates/cloudflare-workers-enterprise/package.json b/lib/plugins/create/templates/cloudflare-workers-enterprise/package.json new file mode 100644 index 00000000000..6bd04587438 --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers-enterprise/package.json @@ -0,0 +1,14 @@ +{ + "name": "cloudflare-workers-enterprise", + "version": "1.0.0", + "description": "Cloudflare serverless deployment for enterprise customers", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "cloudflare", + "license": "MIT", + "devDependencies": { + "serverless-cloudflare-workers": "0.1.0" + } +} diff --git a/lib/plugins/create/templates/cloudflare-workers-enterprise/serverless.yml b/lib/plugins/create/templates/cloudflare-workers-enterprise/serverless.yml new file mode 100644 index 00000000000..abeb14c4793 --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers-enterprise/serverless.yml @@ -0,0 +1,41 @@ +service: + name: hello-world + config: + accountId: CLOUDFLARE_ACCOUNT_ID + zoneId: CLOUDFLARE_ZONE_ID + workers: + hello: + routes: + - example.com/hello/* + foo_script: + routes: + - example.com/foo/* + +provider: + name: cloudflare + +plugins: + - serverless-cloudflare-workers + +functions: + helloWorld: + worker: hello + script: helloWorld + events: + - http: + url: example.com/hello/user + method: GET + headers: + foo: bar + x-client-data: value + + foo: + worker: foo_script + script: bar + events: + - http: + url: example.com/foo/bar + method: GET + headers: + foo: bar + x-client-data: value diff --git a/lib/plugins/create/templates/cloudflare-workers/.gitignore b/lib/plugins/create/templates/cloudflare-workers/.gitignore new file mode 100644 index 00000000000..9e5bccff87d --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers/.gitignore @@ -0,0 +1,3 @@ +# Serverless directories +.serverless +node_modules/ diff --git a/lib/plugins/create/templates/cloudflare-workers/helloWorld.js b/lib/plugins/create/templates/cloudflare-workers/helloWorld.js new file mode 100644 index 00000000000..dbede8a6255 --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers/helloWorld.js @@ -0,0 +1,7 @@ +addEventListener('fetch', event => { + event.respondWith(handleRequest(event.request)) + }) + + async function handleRequest(request) { + return new Response("Hello world") + } diff --git a/lib/plugins/create/templates/cloudflare-workers/package.json b/lib/plugins/create/templates/cloudflare-workers/package.json new file mode 100644 index 00000000000..1ea66bea77b --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers/package.json @@ -0,0 +1,14 @@ +{ + "name": "cloudflare-workers", + "version": "1.0.0", + "description": "Cloudflare serverless deployment for self-serve customers", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "cloudflare", + "license": "MIT", + "devDependencies": { + "serverless-cloudflare-workers": "0.1.0" + } +} diff --git a/lib/plugins/create/templates/cloudflare-workers/serverless.yml b/lib/plugins/create/templates/cloudflare-workers/serverless.yml new file mode 100644 index 00000000000..caaaa91df0d --- /dev/null +++ b/lib/plugins/create/templates/cloudflare-workers/serverless.yml @@ -0,0 +1,27 @@ +service: + name: hello-world + config: + accountId: CLOUDFLARE_ACCOUNT_ID + zoneId: CLOUDFLARE_ZONE_ID + workers: + hello: + routes: + - example.com/hello/* + +provider: + name: cloudflare + +plugins: + - serverless-cloudflare-workers + +functions: + helloWorld: + worker: hello + script: helloWorld # there must be a file called helloWorld.js + events: + - http: + url: example.com/hello/user + method: GET + headers: + foo: bar + x-client-data: value