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

@routup/static

v2.0.0

Published

Routup plugin for serving static files.

Downloads

354

Readme

@routup/static

npm version main codecov Known Vulnerabilities Conventional Commits

This is a plugin for serving static files from a specified directory.

Table of Contents

Installation

npm install @routup/static --save

Documentation

To read the docs, visit https://routup.net

Usage

Create a new middleware function to serve files from within a given directory. When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs.

import { Router } from 'routup';
import { createHandler } from '@routup/static';

const router = new Router();

// serve static files of folder: public
router.use(createHandler('public'));

router.listen(3000);

Multiple Directories

Sometimes it may be necessary to serve static files from multiple directories. To accomplish this, this plugin can be used multiple times. An example of this is shown below:

import { Router } from 'routup';
import { createHandler } from '@routup/static';

const router = new Router();

router.use(createHandler('public'));
router.use(createHandler('files'));

router.listen(3000);

This will allow to serve files from the public and the files directories. When a request for a file is made, those in the public directory will be checked before those in the files directory. If a file with the same name exists in both directories, the one in the public directory will be served.

Mount Path

It is also possible to define a mount path for a root directory. This is done as follows:

import { Router } from 'routup';
import { createHandler } from '@routup/static';

const router = new Router();

router.use('/public', createHandler('public'));

router.listen(3000);

With this setup, requests for files in the public directory must start with /public.

API

Options

The createHandler function takes an optional options object. The available options are:

scan

  • Type: Boolean
  • Default: true
  • Description: Define if the metadata of given files in the directory should be preloaded. The advantage here is, that the filesystem must not be traversed on every request.

cacheMaxAge

  • Type: Number
  • Default: 0
  • Description: Set the max-age (in seconds) directive of the cache-control header.

cacheImmutable

  • Type: Boolean
  • Default: false
  • Description: Append the immutable directive to the cache-control header.

fallback

  • Type: Boolean|String
  • Default: false
  • Description: Resolve files, which are not found to a specific directory (default: '/')

fallbackIgnores

  • Type: RegExp[]
  • Default: []
  • Description: Specify paths/patterns that should not be forwarded to the fallback path.

fallthrough

  • Type: Boolean
  • Default: true
  • Description: Pass the request to the next handler, if no file was found and the fallback strategy is disabled.

extensions

  • Type: String[]
  • Default: ['html', 'htm']
  • Description: Set file extension fallbacks. When set, if a file is not found, the middleware will search for files with the specified extensions and serve the first one that exists.

dotFiles

  • Type: Boolean
  • Default: false
  • Description: Determines how to treat dotfiles (files or directories beginning with a .).

ignores

  • Type: RegExp[]
  • Default: []
  • Description: Specify paths/patterns that should not be served.

License

Made with 💚

Published under MIT License.