Superstatic Static File Server

10.0.0 · active · verified Tue Apr 21

Superstatic is an enhanced static web server designed for modern web applications, currently at version 10.0.0. Originally built to power Firebase Hosting, it provides robust features such as HTML5 pushState support, clean URLs (removing `.html` extensions), advanced caching, and configurable routing via rewrites and redirects. It offers a flexible configuration system through `superstatic.json` or `firebase.json` files. The project maintains an active release cadence, frequently updating dependencies and Node.js engine support, with recent versions focusing on compatibility with newer Node.js LTS releases. Key differentiators include its rich configuration options for dynamic static site behavior, strong support for Single Page Applications (SPAs), and its historical role in Firebase's infrastructure.

Common errors

Warnings

Install

Imports

Quickstart

Initializes and starts a Superstatic server instance programmatically, demonstrating basic configuration for serving a 'public' directory, enabling clean URLs, setting up SPA rewrites, and adding custom cache headers.

import { Server } from 'superstatic';
import * as path from 'path';

async function startStaticServer() {
  const server = new Server({
    port: 8080,
    host: '127.0.0.1',
    cwd: process.cwd(), // Serve from current directory by default
    config: {
      public: 'public', // Serve 'public' directory relative to CWD
      cleanUrls: true,
      rewrites: [{ source: '**', destination: '/index.html' }], // SPA rewrite
      headers: [
        {
          source: '**/*.@(jpg|jpeg|gif|png|svg)',
          headers: [{ key: 'Cache-Control', value: 'max-age=3600' }]
        }
      ]
    }
  });

  const app = server.listen(() => {
    console.log(`Superstatic server running on http://127.0.0.1:8080`);
  });

  // Optional: Handle process exit for graceful shutdown
  process.on('SIGINT', () => {
    console.log('Shutting down server...');
    app.close(() => {
      console.log('Server gracefully shut down.');
      process.exit(0);
    });
  });
}

startStaticServer().catch(console.error);

view raw JSON →