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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

[![Deploy to Fastly](https://deploy.edgecompute.app/button)](https://deploy.edgecompute.app/deploy)

Get to know the Fastly Compute environment with a basic starter that demonstrates routing, simple synthetic responses and code comments that cover common patterns.
Get to know the Fastly Compute environment with a basic starter in TypeScript that demonstrates routing, simple synthetic responses and code comments that cover common patterns.

**For more details about other starter kits for Compute, see the [Fastly Documentation Hub](https://www.fastly.com/documentation/solutions/starters)**

## Features
* TypeScript source files
* `tsconfig.json` file to use as a starting point
* Allow only requests with particular HTTP methods
* Match request URL path and methods for routing
* Build synthetic responses at the edge

## Understanding the code

This starter is intentionally lightweight, and requires no dependencies aside from the [`@fastly/js-compute`](https://www.npmjs.com/package/@fastly/js-compute) npm package. It will help you understand the basics of processing requests at the edge using Fastly. This starter includes implementations of common patterns explained in our [using Compute](https://www.fastly.com/documentation/guides/compute/javascript/) and [VCL migration](https://www.fastly.com/documentation/guides/compute/migrate/) guides.
This starter kit is written in TypeScript and illustrates the same features as the [Compute JavaScript default starter kit](https://github.com/fastly/compute-starter-kit-typescript-default). It is intentionally lightweight, and requires no dependencies aside from the [`@fastly/js-compute`](https://www.npmjs.com/package/@fastly/js-compute) npm package. It will help you understand the basics of processing requests at the edge using Fastly. This starter includes implementations of common patterns explained in our [using Compute](https://www.fastly.com/documentation/guides/compute/javascript/) and [VCL migration](https://www.fastly.com/documentation/guides/compute/migrate/) guides. The starter doesn't require the use of any backends. Once deployed, you will have a Fastly service running on Compute that can generate synthetic responses at the edge.

The starter doesn't require the use of any backends. Once deployed, you will have a Fastly service running on Compute that can generate synthetic responses at the edge.
The Compute JavaScript SDK [has built-in support](https://www.fastly.com/documentation/guides/compute/developer-guides/javascript/#built-in-typescript) for executing TypeScript source files that contain only erasable TypeScript syntax. In this mode, type checking is not performed.

The template uses TypeScript to compile source files in `./src` into JS files in `./build`, which are then wrapped into `./bin/index.wasm` using the `js-compute-runtime` CLI tool bundled with the `@fastly/js-compute` npm package, and bundled into a `.tar.gz` file ready for deployment to Compute.
The SDK does not directly refer to the `tsconfig.json` file, but one is included to aid your IDE in coding support as well as to illustrate the recommended practice of running `tsc --noEmit` in a `prebuild` script to check for TypeScript errors, since the SDK does not perform type checking.

## Running the application

Expand Down
2 changes: 1 addition & 1 deletion fastly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://developer.fastly.com/reference/fastly-toml/

authors = ["<[email protected]>"]
description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules."
description = "A basic TypeScript starter kit that demonstrates routing, simple synthetic responses and overriding caching rules."
language = "javascript"
manifest_version = 3
name = "Default starter for TypeScript"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"@fastly/js-compute": "^3.33.2"
},
"devDependencies": {
"@fastly/cli": "^11.0.0",
"@fastly/cli": "^12.0.0",
"typescript": "^5.2.2"
},
"scripts": {
"prebuild": "tsc",
"build": "js-compute-runtime build/index.js bin/main.wasm",
"prebuild": "tsc --noEmit",
"build": "js-compute-runtime src/index.ts bin/main.wasm",
"start": "fastly compute serve",
"deploy": "fastly compute publish"
}
Expand Down
21 changes: 9 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{
"compilerOptions": {
"strict": true,
"module": "ES2022",
"erasableSyntaxOnly": true,
"skipLibCheck": true,
"target": "ES2022",
"lib": [ "ES2022" ],
"module": "ESNext",
"moduleResolution": "bundler",
"customConditions": [ "fastly" ],
"types": [ "@fastly/js-compute" ],
"esModuleInterop": true,
"lib": [ "ES2022" ],
"rootDir": "src",
"outDir": "build"
},
"include": [
"./src/**/*.js",
"./src/**/*.ts",
],
"exclude": [
"node_modules"
]
"isolatedModules": true,
"verbatimModuleSyntax": true,
"allowImportingTsExtensions": true
}
}