Merge pull request #5258 from pinkerton/master

Add support for Cloudflare Workers
This commit is contained in:
Raees 2018-09-11 20:34:04 +05:00 committed by GitHub
commit f53f04724f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 1506 additions and 0 deletions

View File

@ -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/}
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
@ -157,4 +158,19 @@ Already using AWS or another cloud provider? Read on.
</ul>
</div>
</div>
<div class="docsSection">
<div class="docsSectionHeader">
<a href="./providers/cloudflare/">
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/cf-logo-v-dark-gray.png" width="250" draggable="false"/>
</a>
</div>
<div>
<ul>
<li><a href="./providers/cloudflare/guide/quick-start">Cloudflare Workers QuickStart</a></li>
<li><a href="./providers/cloudflare/guide">Guide</a></li>
<li><a href="./providers/cloudflare/cli-reference">CLI Reference</a></li>
<li><a href="./providers/cloudflare/events">Events</a></li>
</ul>
</div>
</div>
</div>

View File

@ -0,0 +1,71 @@
<!--
title: Serverless - Cloudflare Workers Documentation
menuText: Cloudflare Workers
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/)
<!-- DOCS-SITE-LINK:END -->
# 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)
<div class="docsSections">
<div class="docsSection">
<div class="docsSectionHeader">
<a href="./guide/">
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/guide.png" alt="Serverless Framework Cloudflare Workers Guide" width="250" draggable="false"/>
</a>
</div>
<div class="test">
<ul>
<li><a href="./guide/intro.md">Intro</a></li>
<li><a href="./guide/quick-start.md">Quickstart</a></li>
<li><a href="./guide/installation.md">Installation</a></li>
<li><a href="./guide/services.md">Services</a></li>
<li><a href="./guide/functions.md">Functions</a></li>
<li><a href="./guide/events.md">Events</a></li>
<li><a href="./guide/deploying.md">Deploying</a></li>
<li><a href="./guide/debugging.md">Debugging</a></li>
<li><a href="./guide/workflow.md">Workflow</a></li>
</ul>
</div>
</div>
<div class="docsSection">
<div class="docsSectionHeader">
<a href="./cli-reference/">
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/cli.png" alt="Serverless Framework Cloudflare Workers CLI Reference" width="250" draggable="false"/>
</a>
</div>
<div>
<ul>
<li><a href="./cli-reference/create.md">Create</a></li>
<li><a href="./cli-reference/deploy.md">Deploy</a></li>
<li><a href="./cli-reference/invoke.md">Invoke</a></li>
<li><a href="./cli-reference/remove.md">Remove</a></li>
<li><a href="./cli-reference/plugin-list.md">Plugin List</a></li>
<li><a href="./cli-reference/plugin-search.md">Plugin Search</a></li>
<li><a href="./cli-reference/plugin-install.md">Plugin Install</a></li>
<li><a href="./cli-reference/plugin-uninstall.md">Plugin Uninstall</a></li>
</ul>
</div>
</div>
<div class="docsSection">
<div class="docsSectionHeader">
<a href="./events/">
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/events.png" alt="Serverless Framework Cloudflare Workers Events Reference" width="250" draggable="false"/>
</a>
</div>
<div>
<ul>
<li><a href="./events/http.md">HTTP Events</a></li>
</ul>
</div>
</div>
</div>

View File

@ -0,0 +1,15 @@
<!--
title: Serverless - Cloudflare Workers - CLI Reference
menuText: CLI Reference
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/)
<!-- DOCS-SITE-LINK:END -->
# 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/).

View File

@ -0,0 +1,76 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Create
menuText: create
menuOrder: 1
description: Creates a new Service in your current working directory
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/create)
<!-- DOCS-SITE-LINK:END -->
# 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`.

View File

@ -0,0 +1,50 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Deploy
menuText: deploy
menuOrder: 2
description: Deploy your service to the specified provider
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/deploy)
<!-- DOCS-SITE-LINK:END -->
# 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
```
Youll 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`

View File

@ -0,0 +1,62 @@
<!--
title: Serverless Framework Commands - Fn - Invoke
menuText: invoke
menuOrder: 3
description: Invoke an Fn Function using the Serverless Framework
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/fn/cli-reference/invoke)
<!-- DOCS-SITE-LINK:END -->
# 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.

View File

@ -0,0 +1,42 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Plugin Install
menuText: Plugin Install
menuOrder: 7
description: Install a Serverless plugin
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-install)
<!-- DOCS-SITE-LINK:END -->
# 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 `<pluginname>@<version>` 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
```

View File

@ -0,0 +1,25 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Plugin List
menuText: Plugin List
menuOrder: 5
description: List all available Serverless plugins
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-list)
<!-- DOCS-SITE-LINK:END -->
# 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`

View File

@ -0,0 +1,33 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Plugin Search
menuText: Plugin Search
menuOrder: 6
description: Search through all available Serverless plugins
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-search)
<!-- DOCS-SITE-LINK:END -->
# 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
```

View File

@ -0,0 +1,33 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Plugin Uninstall
menuText: Plugin Uninstall
menuOrder: 8
description: Uninstall a Serverless plugin
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-uninstall)
<!-- DOCS-SITE-LINK:END -->
# 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
```

View File

@ -0,0 +1,21 @@
<!--
title: Serverless Framework Commands - Cloudflare Workers - Remove
menuText: remove
menuOrder: 4
description: Remove a deployed Service and all of its Cloudflare Worker Functions and Services.
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/remove)
<!-- DOCS-SITE-LINK:END -->
# 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`

View File

@ -0,0 +1,18 @@
<!--
title: Serverless - Cloudflare Workers - Events
menuText: Cloudflare Workers Events
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/events/)
<!-- DOCS-SITE-LINK:END -->
# 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/)

View File

@ -0,0 +1,37 @@
<!--
title: Serverless Framework - Cloudflare Workers Events - HTTP Events
menuText: HTTP Events
menuOrder: 1
description: HTTP Events in Cloudflare Workers
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/events/http)
<!-- DOCS-SITE-LINK:END -->
# 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`.

View File

@ -0,0 +1,17 @@
<!--
title: Serverless - Cloudflare Workers
menuText: Guide
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/)
<!-- DOCS-SITE-LINK:END -->
# 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/)

View File

@ -0,0 +1,62 @@
<!--
title: Serverless Framework - Cloudflare Workers Guide - Debugging
menuText: Debugging
menuOrder: 8
description: Recommendations and best practices for debugging Cloudflare Workers with the Serverless Framework
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/debugging)
<!-- DOCS-SITE-LINK:END -->
# 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.

View File

@ -0,0 +1,115 @@
<!--
title: Serverless Framework - Cloudflare Workers Guide - Deploying
menuText: Deploying
menuOrder: 7
description: How to deploy your Cloudflare Workers functions and their required infrastructure
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/deploying)
<!-- DOCS-SITE-LINK:END -->
# 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
```
Youll 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, youll 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.

View File

@ -0,0 +1,39 @@
<!--
title: Serverless Framework - Clouldflare Workers Guide - Events
menuText: Events
menuOrder: 6
description: Configuring Cloudflare Workers Events in the Serverless Framework
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/events)
<!-- DOCS-SITE-LINK:END -->
# 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).

View File

@ -0,0 +1,119 @@
<!--
title: Serverless Framework - Cloudflare Workers Guide - Functions
menuText: Functions
menuOrder: 5
description: How to configure Cloudflare Workers functions in the Serverless Framework
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/functions)
<!-- DOCS-SITE-LINK:END -->
# 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 dont 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 dont 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 Cloudflares 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.

View File

@ -0,0 +1,57 @@
<!--
title: Serverless Framework - Cloudflare Workers Guide - Installing The Serverless Framework and Cloudflare Workers
menuText: Installation
menuOrder: 3
description: How to install the Serverless Framework and start using it with Cloudflare Workers
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/installation)
<!-- DOCS-SITE-LINK:END -->
# Cloudflare Workers - Installation
## Installing Cloudflare Workers
Cloudflare Workers dont 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
```
Youll 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.

View File

@ -0,0 +1,108 @@
<!--
title: Serverless Framework - Cloudflare Workers Guide - Introduction
menuText: Intro
menuOrder: 1
description: An introduction to using Cloudflare Workers with the Serverless Framework.
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/intro)
<!-- DOCS-SITE-LINK:END -->
# 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 Cloudflares 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 dont 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
```
Youll need to redefine your environmental variables after each time you close your terminal.
If youre 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.

View File

@ -0,0 +1,105 @@
<!--
title: Serverless Framework - Workers Guide - Quick Start
menuText: Quick Start
menuOrder: 2
description: Getting started with the Serverless Framework on Cloudflare Workers
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/quick-start)
<!-- DOCS-SITE-LINK:END -->
# 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 domains 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
```
Youll 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
```

View File

@ -0,0 +1,202 @@
<!--
title: Serverless Framework - Cloudflare Workers Guide - Services
menuText: Services
menuOrder: 4
description: How to manage and configure Serverless services, which contain your Cloudflare Workers and their events.
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/services)
<!-- DOCS-SITE-LINK:END -->
# 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 dont 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 Cloudflares 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
```

View File

@ -0,0 +1,58 @@
<!--
title: Serverless Framework Guide - Cloudflare Workers - Workflow
menuText: Workflow
menuOrder: 9
description: A guide and cheatsheet containing CLI commands and workflow recommendations.
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/workflow)
<!-- DOCS-SITE-LINK:END -->
# 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 workers 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]
```

View File

@ -34,6 +34,8 @@ const validTemplates = [
'aws-go',
'aws-go-dep',
'azure-nodejs',
'cloudflare-workers',
'cloudflare-workers-enterprise',
'fn-nodejs',
'fn-go',
'google-nodejs',

View File

@ -0,0 +1,3 @@
# Serverless directories
.serverless
node_modules/

View File

@ -0,0 +1,7 @@
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
return new Response("Foo is not Bar")
}

View File

@ -0,0 +1,7 @@
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
return new Response("Hello world")
}

View File

@ -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"
}
}

View File

@ -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

View File

@ -0,0 +1,3 @@
# Serverless directories
.serverless
node_modules/

View File

@ -0,0 +1,7 @@
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
return new Response("Hello world")
}

View File

@ -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"
}
}

View File

@ -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