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

@matthewp/astro-fastify

v3.2.0

Published

A Fastify integration for Astro

Downloads

111

Readme

npm version number

@matthewp/astro-fastify

An fastify adapter to use in Astro projects. @matthewp/astro-fastify allows you to use fastify and Astro side-by-side, and deploy your apps to Node.js powered by a battle-tested HTTP server.

Unlike most adapters, @matthewp/astro-fastify also works in dev mode.

install

@matthewp/astro-fastify is needed in production so use --save.

npm install @matthewp/astro-fastify --save

Usage

@matthewp/astro-fastify is used like any other adapter for Astro. Import and use it in your astro.config.mjs file:

import fastify from '@matthewp/astro-fastify';

/** @type {import('astro').AstroUserConfig} */
export default {
  output: 'server',
  adapter: fastify({
    entry: new URL('./api/index.ts', import.meta.url)
  })
};

Options

entry

Specifies the entry point to define fastify routes and plugins. This module must export a default function that takes in the Fastify instance, where you can define routes and registry plugins.

api/index.ts

import type { DefineFastifyRoutes } from '@matthewp/astro-fastify';

const defineRoutes: DefineFastifyRoutes = (fastify) => {
  fastify.get('/api/todos', function(request, reply) {
    reply.send({
      todos: [
        { label: 'eat lunch' },
        { label: 'exercise' },
        { label: 'walk the dog' }
      ]
    });
  })
};

export default defineRoutes;

port

Specifies the port to use in production. Most hosts will set process.env.PORT and that will be used, so setting this option is unnecessary. If you do set port it will override host-specific config.

In development mode this option has no effect, as fastify runs on the same server as Astro.

logger

Specifies the Fastify logging options. See the Fastify docs to see the options. Note that these options are built into the production bundle, so options such as logger.stream do not work.

Note on route priority

Fastify runs in front of Astro's own routing, which means that any routes you define in fastify take priority over routes defined in Astro. So if, for example, you have conflicting routes the Astro route will never be hit.

Production usage

@matthewp/astro-fastify automatically configures Astro to build your fastify routes into your production build. Run your build as normal:

astro build

Or if you have an npm script:

npm run build

Which will create an entrypoint for your server, by default dist/server/entry.mjs. Running this file in Node.js automatically starts the fastify server:

node dist/server/entry.mjs

Configure your host to run this script. Assets and JavaScript are output to dist/client/assets/. You can configure your CDN to serve these files more efficiently and with long-lived cache headers.

License

BSD-2-Clause