@virke/sveltekit-adapter
v1.1.0
Published
SvelteKit adapter for Virke/Fastly Compute.
Readme
@virke/sveltekit-adapter
SvelteKit adapter for Virke/Fastly Compute.
Features
- Static assets → Object Storage (served free via VCL)
- SSR routes → Fastly Compute service (StarlingMonkey Wasm)
- Virke bindings available in hooks and endpoints:
env.db,env.kv,env.os3
Installation
bun add -D @virke/sveltekit-adapterConfiguration
In svelte.config.js:
import adapter from '@virke/sveltekit-adapter'
export default {
kit: {
adapter: adapter({
staticDir: 'build/static', // Static assets output
serverDir: 'build/server', // SSR server bundle output
prerender: true // Include prerendered pages in static
})
}
}Using Virke Bindings
Initialize in hooks
src/hooks.server.ts:
import { initVirke } from '@virke/sveltekit-adapter'
export const virke = initVirke({
db: 'my-database', // Virke DB name
kv: 'my_kv_store', // KV Store resource link name
os3: 'my-bucket' // Object Storage bucket
})
export async function handle({ event, resolve }) {
// Attach Virke bindings to event.locals
event.locals.virke = virke
return resolve(event)
}Use in routes
src/routes/+page.server.ts:
export const load = async ({ locals }) => {
const users = await locals.virke.db.query("SELECT * FROM users")
const settings = await locals.virke.kv.getJson("app:settings")
return { users, settings }
}src/routes/api/upload/+server.ts:
export const POST = async ({ request, locals }) => {
const data = await request.formData()
const file = data.get('file')
if (file instanceof File) {
const buffer = await file.arrayBuffer()
await locals.virke.os3.put(`uploads/${file.name}`, buffer, file.type)
return new Response('OK', { status: 200 })
}
return new Response('Bad Request', { status: 400 })
}Deployment
1. Build the app
bun run build2. Deploy static assets to Object Storage
virke deploy static build/static3. Deploy SSR server to Fastly Compute
cd build/server
fastly compute build
fastly compute deployTypeScript Support
Add to src/app.d.ts:
import type { VirkeDB, VirkeKV, VirkeOS3 } from '@virke/runtime'
declare global {
namespace App {
interface Locals {
virke: {
db: VirkeDB
kv: VirkeKV
os3: VirkeOS3
}
}
}
}
export {}Architecture
- Static files (CSS, JS, images, prerendered HTML) are uploaded to Fastly Object Storage and served via free VCL service
- SSR routes run on a dedicated Fastly Compute service using StarlingMonkey (JS runtime compiled to Wasm)
- Virke bindings provide access to Virke DB (SQL), Virke KV (key-value), and Virke OS3 (object storage)
License
MIT
