Code Monkey home page Code Monkey logo

sveltekit-adapter-fastly-compute's Introduction

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 = ["[email protected]"]
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;
+		};
	}
}

sveltekit-adapter-fastly-compute's People

Contributors

lobidu avatar

Stargazers

Daniel Mantei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.