Database Setup
Create a Redis database using Upstash Console or Upstash CLI. Select the global to minimize the latency from all edge locations. Copy theUPSTASH_REDIS_REST_URL
and
UPSTASH_REDIS_REST_TOKEN
for the next steps.
Project Setup
We will use Fastly CLI for deployment, so please install Fastly CLI. Create a folder for your project and runfastly init
. Select [2] JavaScript
,
then [2] Empty starter for JavaScript
fastly compute publish
. You need to add your Upstash database’s endpoint as a
backend and select 443 as its port.
The Code
Updatesrc/index.js
as below:
Deploy
Deploy:fastly compute deploy
After deployment, the CLI logs the endpoint. You can check the logs with:
fastly log-tail --service-id=<YOUR_FASTLY_SERVICE_ID>
Run Locally
To run the function locally add the backend to yourfastly.toml
as below:
fastly compute serve