Svelte Demo D1 screenshot

Svelte Demo D1

Author Avatar Theme by Elithrar
Updated: 10 Jul 2023
16 Stars

Cloudflare Pages + SvelteKit + Cloudflare D1 - https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site/#deploy-with-cloudflare-pages

Categories

Overview

The example mentioned in this article is a SvelteKit project that utilizes Cloudflare Pages and connects to a D1 database. It provides instructions on how to set up and deploy the project, as well as how to access the D1 database from a server endpoint.

Features

  • SvelteKit integration with Cloudflare Pages
  • Connection to a D1 database
  • Deployment using Cloudflare Pages
  • Accessing D1 from server endpoints

Installation

To install the SvelteKit project with Cloudflare D1, follow these steps:

  1. Update the svelte.config.ts file to import adapter from @sveltejs/adapter-cloudflare instead of adapter-auto.
import adapter from '@sveltejs/adapter-cloudflare';
  1. Expand the Platform interface in the src/app.d.ts file to include the necessary code for connecting to the D1 database. The exact code is not provided in the given content.

  2. Create the Cloudflare Pages project by connecting it to your GitHub repository. Refer to the official Cloudflare documentation (link provided in the content) for detailed instructions on how to deploy a Svelte site with Cloudflare Pages.

  3. Bind your D1 database to the project. Make sure the binding name in the Cloudflare Pages project matches what you defined in the src/app.d.ts file (in this example, it’s “DB”). The Cloudflare documentation (link provided in the content) provides information on how to bind D1 databases in Cloudflare Pages.

  4. Re-deploy the application after making the necessary configuration changes and bindings.

Summary

This article showcases an example SvelteKit project that utilizes Cloudflare Pages and connects to a D1 database. It provides installation instructions and guidance on accessing the D1 database from server endpoints. However, the specific code details are not provided in the given content, and the example application is not officially supported by Cloudflare.