Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-simple-static

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-simple-static

Simple caching static file server for Koa

  • 4.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-88.89%
Maintainers
1
Weekly downloads
 
Created
Source

Koa Simple Static

Simple caching static file server for Koa

ko-fi Support with PayPal


Similar to koa-static-cache, but with different options, better API, and in TypeScript.

Features:

  • Caches: preloads files and dynamically loads new ones if found
  • Falls back to /index.html if available
  • Gzips if request's accept-encoding includes gzip
  • Accepts extra headers for served files

Installation

npm i koa-simple-static

Usage

app.use(serve({
  dir: process.cwd()
}))

Options

  • dir: string — directory you want to serve
  • maxAge?: number = 0 — cache control max age (in seconds)
  • extraHeaders?: Object[] — any extra headers you wish to set for requests served by this module
    • The format for this is [ { 'Link': '</foo.js>; rel=preload; as=script' }, { 'Set-Cookie': 'foo=bar; path=/;' } ]

Example

import serve from 'koa-simple-static'
import { resolve } from 'path'
import Koa from 'koa'

const app = new Koa()
const port = process.env.PORT || 4444

app.use(serve({
  dir: resolve(__dirname, 'public'),
  extraHeaders: [ { 'X-Something-Whatever': 'foo, bar' } ]
}))

app.listen(port, () => {
  console.log(`Serving on ${port}!`)
})

Important if you're using require, you'll need to require('koa-simple-static').default.

FAQ

  • How is this different from other options?
    • Before this module, you could have a static file server for Koa with good defaults that didn't cache, or one that did cache with weird defaults (like not falling back to index.html). Now, you can have the good parts of both.
  • I'm getting errors but my code is fine?
    • How old is your version of Node? You'll need to be on the versions supported in the engines field, or else Babelify or otherwise compile your server.

Contributing

  • Issues and PRs are welcome! Please keep in mind that this is feature complete.
  • This project uses TypeScript. It will be easiest if your editor is configured to work with eslint and tsc.
  • Please run tests!
  • If you're changing or adding functionality, please add tests!

LICENSE

Keywords

FAQs

Package last updated on 26 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc