Skip to content

Commit

Permalink
chore: correct documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Jul 12, 2023
1 parent 913eb40 commit 671bcea
Show file tree
Hide file tree
Showing 54 changed files with 198,490 additions and 663 deletions.
197,992 changes: 197,992 additions & 0 deletions documentation/app/fastly.toml

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions documentation/docs/fastly:cache/SimpleCache/get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If the key does exist in the cache, this returns a `SimpleCacheEntry`.

## Examples

In this example we attempt to retrieve an entry from the Fastly Cache, if the entry does not exist, we create the content and insert it into the Fastly Cache before finally returning.
In this example we attempt to retrieve an entry from the Fastly Cache, and return a message stating whether the entry was in the Fastly Cache or not.

```js
/// <reference types="@fastly/js-compute" />
Expand All @@ -47,14 +47,9 @@ import { SimpleCache } from 'fastly:cache';
addEventListener('fetch', event => event.respondWith(app(event)));

async function app(event) {
const path = new URL(event.request).pathname;
const path = new URL(event.request.url).pathname;
let page = SimpleCache.get(path);
if (!page) {
page = await render(path);
// Store the page in the cache for 1 minute.
SimpleCache.set(path, page, 60);
}
return new Response(page, {
return new Response(page ? `${path} is in the cache` : `${path} is not in the cache`, {
headers: {
'content-type': 'text/plain;charset=UTF-8'
}
Expand Down
77 changes: 0 additions & 77 deletions documentation/docs/fastly:cache/SimpleCache/set.mdx

This file was deleted.

4 changes: 2 additions & 2 deletions documentation/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Fiddle} from '@site/src/components/fiddle';

# JavaScript for Compute@Edge

This site is the full SDK reference for [@fastly/js-compute](https://www.npmjs.com/package/@fastly/js-compute), the module that provides the interface between your JavaScript code and the [Fastly](https://www.fastly.com) Compute@Edge platform.
This site is the full SDK reference for [`@fastly/js-compute`](https://www.npmjs.com/package/%40fastly/js-compute), the module that provides the interface between your JavaScript code and the [Fastly](https://www.fastly.com) Compute@Edge platform.

If you haven't used Compute@Edge before, start by [setting up your first Compute@Edge program](https://developer.fastly.com/learning/compute/) over on **developer.fastly.com** so that you have a working development environment.

Expand Down Expand Up @@ -95,4 +95,4 @@ addEventListener("fetch", event => {

</Fiddle>

Check out [`fiddle.fastly.dev`](https://fiddle.fastly.dev] to create your own.
Check out [`fiddle.fastly.dev`](https://fiddle.fastly.dev) to create your own.
47 changes: 23 additions & 24 deletions documentation/versioned_docs/version-1.0.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,41 @@ pagination_prev: null

import {Fiddle} from '@site/src/components/fiddle';

# Getting started
# JavaScript for Compute@Edge

First, make sure to have [Fastly's CLI](https://developer.fastly.com/learning/tools/cli/) installed:
This site is the full SDK reference for [`@fastly/js-compute`](https://www.npmjs.com/package/%40fastly/js-compute), the module that provides the interface between your JavaScript code and the [Fastly](https://www.fastly.com) Compute@Edge platform.

The Fastly CLI is available for multiple operating systems.
If you haven't used Compute@Edge before, start by [setting up your first Compute@Edge program](https://developer.fastly.com/learning/compute/) over on **developer.fastly.com** so that you have a working development environment.

- **MacOS**: Install from Homebrew:
To learn more about the fundamentals of using JavaScript with Compute@Edge, see our [using JavaScript](https://developer.fastly.com/learning/compute/javascript/) guide.

```
brew install fastly/tap/fastly
```
## Understanding the JavaScript SDK

- **Windows**: [Visit the GitHub repository](https://github.com/fastly/cli/releases/latest) to download the prebuilt binary for your architecture.
- **Linux**: Packages are available for many distributions, along with prebuilt binaries. [Visit the GitHub repository](https://github.com/fastly/cli/releases/latest) to download the package for your distribution.
Incoming HTTP requests to [domains that are attached to your Fastly service](https://developer.fastly.com/learning/concepts/) will start an instance of your application and invoke a `fetch` event, which can be bound using the `addEventListener` function:

## Initialise a new project
```js
addEventListener("fetch", event => event.respondWith(handleRequest(event)) );

Create a new Fastly Compute@Edge JavaScript project:
async function handleRequest(event) {
const req = event.request;

```shell
fastly compute init --language javascript --from https://github.com/fastly/compute-starter-kit-javascript-empty
return fetch(req, {
backend: "example_backend"
});
}
```

Install the dependencies:
Fastly specific features are available as named imports from `fastly:` prefixed modules, all of which are documented in this site. For example, the [env](https://js-compute-reference-docs.edgecompute.app/docs/fastly:env/env) function provides access to [environment variables](https://developer.fastly.com/reference/compute/ecp-env/) and can be imported into your application like this:

```
npm install
```js
import { env } from "fastly:env"
```

## Try it out locally
JavaScript code compiled for Compute@Edge has access to a global environment with most of the globals you would expect in an ECMAScript runtime, like [`Date`](https://js-compute-reference-docs.edgecompute.app/docs/globals/Date/) and [`console`](https://js-compute-reference-docs.edgecompute.app/docs/globals/console/log).

## Trying things out

```shell
fastly compute serve --watch
```

Your application should now be running on [http://localhost:7676](http://localhost:7676)

[Fastly fiddle](https://fiddle.fastly.dev) is an online web-based playground where you can run Fastly code. You'll see fiddles included in many pages of our [developer hub](https://developer.fastly.com) and this SDK reference. These interactive examples can be executed right on the page by clicking the **RUN** tab:

<Fiddle config={{
"type": "javascript",
Expand All @@ -54,7 +51,7 @@ Your application should now be running on [http://localhost:7676](http://localho
"https://http-me.glitch.me"
],
"src": {
"deps": "{\n \"@fastly/js-compute\": \"^1.0.0\"\n}",
"deps": "{\n \"@fastly/js-compute\": \"^1.0.1\"\n}",
"main": `
/// <reference types="@fastly/js-compute" />
async function app(event) {
Expand Down Expand Up @@ -97,3 +94,5 @@ addEventListener("fetch", event => {
```

</Fiddle>

Check out [`fiddle.fastly.dev`](https://fiddle.fastly.dev) to create your own.
44 changes: 22 additions & 22 deletions documentation/versioned_docs/version-1.1.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,41 @@ pagination_prev: null

import {Fiddle} from '@site/src/components/fiddle';

# Getting started
# JavaScript for Compute@Edge

First, make sure to have [Fastly's CLI](https://developer.fastly.com/learning/tools/cli/) installed:
This site is the full SDK reference for [`@fastly/js-compute`](https://www.npmjs.com/package/%40fastly/js-compute), the module that provides the interface between your JavaScript code and the [Fastly](https://www.fastly.com) Compute@Edge platform.

The Fastly CLI is available for multiple operating systems.
If you haven't used Compute@Edge before, start by [setting up your first Compute@Edge program](https://developer.fastly.com/learning/compute/) over on **developer.fastly.com** so that you have a working development environment.

- **MacOS**: Install from Homebrew:
To learn more about the fundamentals of using JavaScript with Compute@Edge, see our [using JavaScript](https://developer.fastly.com/learning/compute/javascript/) guide.

```
brew install fastly/tap/fastly
```
## Understanding the JavaScript SDK

- **Windows**: [Visit the GitHub repository](https://github.com/fastly/cli/releases/latest) to download the prebuilt binary for your architecture.
- **Linux**: Packages are available for many distributions, along with prebuilt binaries. [Visit the GitHub repository](https://github.com/fastly/cli/releases/latest) to download the package for your distribution.
Incoming HTTP requests to [domains that are attached to your Fastly service](https://developer.fastly.com/learning/concepts/) will start an instance of your application and invoke a `fetch` event, which can be bound using the `addEventListener` function:

## Initialise a new project
```js
addEventListener("fetch", event => event.respondWith(handleRequest(event)) );

Create a new Fastly Compute@Edge JavaScript project:
async function handleRequest(event) {
const req = event.request;

```shell
fastly compute init --language javascript --from https://github.com/fastly/compute-starter-kit-javascript-empty
return fetch(req, {
backend: "example_backend"
});
}
```

Install the dependencies:
Fastly specific features are available as named imports from `fastly:` prefixed modules, all of which are documented in this site. For example, the [env](https://js-compute-reference-docs.edgecompute.app/docs/fastly:env/env) function provides access to [environment variables](https://developer.fastly.com/reference/compute/ecp-env/) and can be imported into your application like this:

```
npm install
```js
import { env } from "fastly:env"
```

## Try it out locally
JavaScript code compiled for Compute@Edge has access to a global environment with most of the globals you would expect in an ECMAScript runtime, like [`Date`](https://js-compute-reference-docs.edgecompute.app/docs/globals/Date/) and [`console`](https://js-compute-reference-docs.edgecompute.app/docs/globals/console/log).

## Trying things out

```shell
fastly compute serve --watch
```

Your application should now be running on [http://localhost:7676](http://localhost:7676)
[Fastly fiddle](https://fiddle.fastly.dev) is an online web-based playground where you can run Fastly code. You'll see fiddles included in many pages of our [developer hub](https://developer.fastly.com) and this SDK reference. These interactive examples can be executed right on the page by clicking the **RUN** tab:

<Fiddle config={{
"type": "javascript",
Expand Down Expand Up @@ -96,3 +94,5 @@ addEventListener("fetch", event => {
```

</Fiddle>

Check out [`fiddle.fastly.dev`](https://fiddle.fastly.dev) to create your own.
44 changes: 22 additions & 22 deletions documentation/versioned_docs/version-1.10.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,41 @@ pagination_prev: null

import {Fiddle} from '@site/src/components/fiddle';

# Getting started
# JavaScript for Compute@Edge

First, make sure to have [Fastly's CLI](https://developer.fastly.com/learning/tools/cli/) installed:
This site is the full SDK reference for [`@fastly/js-compute`](https://www.npmjs.com/package/%40fastly/js-compute), the module that provides the interface between your JavaScript code and the [Fastly](https://www.fastly.com) Compute@Edge platform.

The Fastly CLI is available for multiple operating systems.
If you haven't used Compute@Edge before, start by [setting up your first Compute@Edge program](https://developer.fastly.com/learning/compute/) over on **developer.fastly.com** so that you have a working development environment.

- **MacOS**: Install from Homebrew:
To learn more about the fundamentals of using JavaScript with Compute@Edge, see our [using JavaScript](https://developer.fastly.com/learning/compute/javascript/) guide.

```
brew install fastly/tap/fastly
```
## Understanding the JavaScript SDK

- **Windows**: [Visit the GitHub repository](https://github.com/fastly/cli/releases/latest) to download the prebuilt binary for your architecture.
- **Linux**: Packages are available for many distributions, along with prebuilt binaries. [Visit the GitHub repository](https://github.com/fastly/cli/releases/latest) to download the package for your distribution.
Incoming HTTP requests to [domains that are attached to your Fastly service](https://developer.fastly.com/learning/concepts/) will start an instance of your application and invoke a `fetch` event, which can be bound using the `addEventListener` function:

## Initialise a new project
```js
addEventListener("fetch", event => event.respondWith(handleRequest(event)) );

Create a new Fastly Compute@Edge JavaScript project:
async function handleRequest(event) {
const req = event.request;

```shell
fastly compute init --language javascript --from https://github.com/fastly/compute-starter-kit-javascript-empty
return fetch(req, {
backend: "example_backend"
});
}
```

Install the dependencies:
Fastly specific features are available as named imports from `fastly:` prefixed modules, all of which are documented in this site. For example, the [env](https://js-compute-reference-docs.edgecompute.app/docs/fastly:env/env) function provides access to [environment variables](https://developer.fastly.com/reference/compute/ecp-env/) and can be imported into your application like this:

```
npm install
```js
import { env } from "fastly:env"
```

## Try it out locally
JavaScript code compiled for Compute@Edge has access to a global environment with most of the globals you would expect in an ECMAScript runtime, like [`Date`](https://js-compute-reference-docs.edgecompute.app/docs/globals/Date/) and [`console`](https://js-compute-reference-docs.edgecompute.app/docs/globals/console/log).

## Trying things out

```shell
fastly compute serve --watch
```

Your application should now be running on [http://localhost:7676](http://localhost:7676)
[Fastly fiddle](https://fiddle.fastly.dev) is an online web-based playground where you can run Fastly code. You'll see fiddles included in many pages of our [developer hub](https://developer.fastly.com) and this SDK reference. These interactive examples can be executed right on the page by clicking the **RUN** tab:

<Fiddle config={{
"type": "javascript",
Expand Down Expand Up @@ -96,3 +94,5 @@ addEventListener("fetch", event => {
```

</Fiddle>

Check out [`fiddle.fastly.dev`](https://fiddle.fastly.dev) to create your own.

0 comments on commit 671bcea

Please sign in to comment.