Skip to content

Commit

Permalink
Merge pull request #9 from fastly/kats/cli-deps
Browse files Browse the repository at this point in the history
Use @fastly/cli in the starter kit
  • Loading branch information
harmony7 authored Sep 30, 2024
2 parents 96dbe7e + e52ad26 commit 9bb04e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,47 @@ This is the entry point of the application, an event-listener is attached to the

This is where the majority of our application code lives. A single async function is exported named `app`, which is the function that recieves the incoming `FetchEvent` and returns a `Response` instance, which will be sent to the user-agent.

## Running the application

To create an application using this starter kit, create a new directory for your application and switch to it, and then type the following command:

```shell
npm create @fastly/compute@latest -- --language=typescript --starter-kit=kv-store
```

To build and run your new application in the local development environment, type the following command:

```shell
npm run start
```

## Deploying the project to Fastly

Note that Fastly Services have to have unique names within a Fastly Account.

To create and deploy to a new Fastly Service run the command and follow the instructions:

```shell
fastly compute publish
npm run deploy
```

That is it, we now have a Fastly Service, a Fastly KV Store and have them linked together!

You can view real-time logs for the Fastly Service by running:
```shell
fastly log-tail
npx fastly log-tail
```

## Adding entries to the KV Store

It is possible to add key-value pairs to an KV Store using the Fastly CLI like so:
```shell
fastly kv-store-entry create --store-id=$FASTLY_KV_STORE_ID --key-name=$KEY --value=$VALUE
npx fastly kv-store-entry create --store-id=$FASTLY_KV_STORE_ID --key-name=$KEY --value=$VALUE
```

For example, here is how you could add to the KV Store named `my-store` a key named `readme` whose value is the contents of `README.md`:
```shell
fastly kv-store-entry create --store-id="$(fastly kv-store list --json | jq -r '.Data[]|select(.Name=="my-store").ID')" --key-name="readme" --value="$(cat README.md)"
npx fastly kv-store-entry create --store-id="$(npx fastly kv-store list --json | jq -r '.Data[]|select(.Name=="my-store").ID')" --key-name="readme" --value="$(cat README.md)"
```

## Security issues
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"node": "^18.0.0"
},
"devDependencies": {
"@fastly/cli": "^10.14.0",
"typescript": "^5.0.0"
},
"dependencies": {
Expand All @@ -15,6 +16,7 @@
"scripts": {
"prebuild": "tsc",
"build": "js-compute-runtime build/index.js bin/main.wasm",
"deploy": "npm run build && fastly compute deploy"
"start": "fastly compute serve",
"deploy": "fastly compute publish"
}
}

0 comments on commit 9bb04e6

Please sign in to comment.