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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thinkeloquent/core-static-app

v1.0.3

Published

Fastify plugin for serving static files with SPA support

Readme

@thinkeloquent/core-static-app

A Fastify plugin for serving static files with SPA (Single Page Application) support. Perfect for serving Vite-built applications.

Features

  • Serve static files from any directory
  • SPA mode with automatic fallback to index.html for client-side routing
  • Configurable URL prefix
  • Cache control headers
  • ETag support
  • Pre-compressed file serving (.gz, .br)
  • TypeScript support with full type definitions
  • Zod schema validation for options

Installation

npm install @thinkeloquent/core-static-app

Usage

Basic Usage

import Fastify from 'fastify';
import coreStaticApp from '@thinkeloquent/core-static-app';

const fastify = Fastify();

await fastify.register(coreStaticApp, {
  root: '/path/to/static/files',
  prefix: '/',
});

await fastify.listen({ port: 3000 });

Serving a Vite App with SPA Support

import Fastify from 'fastify';
import coreStaticApp from '@thinkeloquent/core-static-app';
import { join } from 'path';

const fastify = Fastify();

await fastify.register(coreStaticApp, {
  root: join(__dirname, '../../frontend/dist'),
  prefix: '/',
  spa: true, // Enable SPA mode for React/Vue routing
  maxAge: 86400, // Cache for 1 day
});

await fastify.listen({ port: 3000 });

Development Mode (No Caching)

For development, you can disable caching by setting maxAge: 0:

await fastify.register(coreStaticApp, {
  root: join(__dirname, '../../frontend/dist'),
  prefix: '/',
  spa: true,
  maxAge: 0, // Disable caching for development
});

This will set the following headers:

  • Cache-Control: no-cache, no-store, must-revalidate
  • Pragma: no-cache
  • Expires: 0

Multiple Static Directories

// Serve main app
await fastify.register(coreStaticApp, {
  root: '/path/to/app',
  prefix: '/app',
  spa: true,
});

// Serve admin panel
await fastify.register(coreStaticApp, {
  root: '/path/to/admin',
  prefix: '/admin',
  spa: true,
});

// Serve assets
await fastify.register(coreStaticApp, {
  root: '/path/to/assets',
  prefix: '/assets',
  maxAge: 604800, // Cache for 7 days
});

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | root | string | required | Root directory to serve static files from | | prefix | string | '/' | URL prefix for serving static files | | spa | boolean | false | Enable SPA mode - fallback to index.html for 404s | | maxAge | number | 86400 | Maximum age for cache-control header (in seconds). Set to 0 to disable caching with no-cache headers | | dotfiles | boolean | false | Enable serving dotfiles | | index | string[] | ['index.html'] | Index files to serve automatically | | etag | boolean | true | Enable etag generation | | preCompressed | boolean | false | Enable serving pre-compressed files (.gz, .br) |

SPA Mode

When spa: true is enabled:

  1. GET requests without file extensions or ending in .html will fallback to index.html
  2. Routes starting with /api are excluded from fallback (preserved for API endpoints)
  3. Static assets (files with extensions like .js, .css, .png) are served normally
  4. This enables client-side routing for React, Vue, or other SPA frameworks

TypeScript

The plugin is fully typed and exports all necessary types:

import coreStaticApp, {
  type StaticAppOptions,
  type StaticAppResult,
  StaticAppOptionsSchema
} from '@thinkeloquent/core-static-app';

// Access plugin result
fastify.register(coreStaticApp, options);

// Later in your code
console.log(fastify.staticAppResult);
// {
//   success: true,
//   root: '/absolute/path/to/files',
//   prefix: '/',
//   spaMode: true
// }

Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Watch mode
npm run test:watch

# Type check
npm run typecheck

License

MIT