npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-adapter-fastify

v0.0.15

Published

SvelteKit Adapter for Fastify.

Downloads

39

Readme

svelte-adapter-fastify

License: MIT code style: prettier npm version codecov Main WorkFlow CodeQL WorkFlow

svelte-adapter-fastify is a SvelteKit plugin for the Fastify framework.

| :warning: WARNING: This project is considered to be in BETA until SvelteKit is available for general use and the Adapter API is stable! | | ----------------------------------------------------------------------------------------------------------------------------------------- |

Beta Adapter Version Compatibility

| Adapter Version | SvelteKit Version | | --------------- | ----------------- | | 0.0.14 | 1.0.0-next.377 | | 0.0.13 | 1.0.0-next.377 | | 0.0.12 | 1.0.0-next.377 | | 0.0.11 | 1.0.0-next.377 | | 0.0.10 | 1.0.0-next.377 |

Note: only the versions listed have been tested together, if others happen to work, it is just coincidence. This is beta software after all.

Supported Fastify versions

  • Fastify v4.x

Supported Node.js versions

The latest versions of the following Node.js versions are tested and supported.

  • 16
  • 18

Quick Start

Install the package using npm:

npm i --save-exact svelte-adapter-fastify

or yarn:

yarn add svelte-adapter-fastify

or pnpm:

pnpm add --save-exact svelte-adapter-fastify

Setup

Replace the default @sveltejs/adapter-auto with svelte-adapter-fastify in the svelte.config.js file:

import preprocess from 'svelte-preprocess';
- import adapter from '@sveltejs/adapter-auto';
+ import fastifyAdapter from "svelte-adapter-fastify";

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: preprocess(),
  kit: {
-   adapter: adapter(),
+   adapter: fastifyAdapter(),
  },
  methodOverride: {
    allowed: ['PATCH', 'DELETE'],
  }
};

export default config;

Then:

npm run build

Which will generate the Fastify server ./build/server/index.js which can be run:

PORT=3000 node ./build/server/index.js

Custom Fastify Server

To run a customized server, start by copying the default server from the svelte-adapter-fastify module:

mkdir -p adapter/fastify
cp node_modules/svelte-adapter-fastify/files/index.js adapter/fastify
cp node_modules/svelte-adapter-fastify/files/server.js adapter/fastify

Edit the adapter/fastify/index.js and adapter/fastify/index.js files to meet your needs. You can add routes and other plugins to the custom Fastify server.

By default the server will listen on localhost, if you are deploying on GCP or in a Dockerfile then you would need to set the HOST environment variable to 0.0.0.0.

HOST=0.0.0.0 PORT=3000 node ./build/server/index.js

A very important note: Any changes to the adapter/fastify/index.js or adapter/fastify/server.js file will only reflect after a new build.

At build time refer to this custom server. When configuring the adapter in svelte.config.js, add both serverFile and startFile parameters:

import preprocess from 'svelte-preprocess';
import fastifyAdapter from 'svelte-adapter-fastify';
+ import path from 'node:path';

+ const __dirname = path.resolve();

const config = {
  preprocess: preprocess(),
  kit: {
    adapter: fastifyAdapter({
+     serverFile: path.join(__dirname, './adapter/fastify/server.js'),
+     startFile: path.join(__dirname, './adapter/fastify/index.js'),
    }),
  },
  methodOverride: {
    allowed: ['PATCH', 'DELETE'],
  }
};

export default config;

Build / Run as normal

npm run build
PORT=3000 node ./build/server/index.js