Skip to content

Lobidu/sveltekit-adapter-fastly-compute

Repository files navigation

sveltekit-adapter-fastly-compute

NOTE: This project is under active development. It is not functional yet. Feel free to contribute!

SvelteKit adapter that creates a Fastly Compute@Edge site using a function for dynamic server rendering. Based on sveltekit's own adapter-cloudflare-workers

Usage

Install with npm i -D sveltekit-adapter-fastly-compute, then add the adapter to your svelte.config.js:

import adapter from 'sveltekit-adapter-fastly-compute';

export default {
  kit: {
    adapter: adapter()
  }
};

Basic Configuration

This adapter expects to find a fastly.toml file in the project root. It should look something like this:

manifest_version = 2
name = "my-compute-project"
description = "A wonderful Compute@Edge project that adds edge computing goodness to my application architecture."
authors = ["me@example.com"]
language = "javascript"
service_id = "SU1Z0isxPaozGVKXdv0eY"

If you have not done so before, install the Fastly CLI. After installing, configure it with:

fastly profile create

Then, you can build your app and deploy it:

fastly publish

Environment variables

The env object, containing KV/DO namespaces etc, is passed to SvelteKit via the platform property along with context and caches, meaning you can access it in hooks and endpoints:

export async function POST({ request, platform }) {
  const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
}

To make these types available to your app, reference them in your src/app.d.ts:

/// <reference types="@sveltejs/kit" />
+/// <reference types="sveltekit-adapter-fastly-compute" />

declare namespace App {
	interface Platform {
+		env?: {
+			YOUR_KV_NAMESPACE: KVNamespace;
+			YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
+		};
	}
}

About

A sveltekit adapter for Fastly's Compute@Edge

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published