Simple caching static file server for Koa
Similar to koa-static-cache, but with different options, better API, and in TypeScript.
Features:
/index.html
if availableaccept-encoding
includes gzipapp.use(serve({ dir: process.cwd() }))
dir: string
— directory you want to servemaxAge?: number = 0
— cache control max age (in seconds)extraHeaders?: Object[]
— any extra headers you wish to set for requests served by this module
[ { 'Link': '</foo.js>; rel=preload; as=script' }, { 'Set-Cookie': 'foo=bar; path=/;' } ]
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
.
index.html
). Now, you can have the good parts of both.engines
field, or else Babelify or otherwise compile your server.eslint
and tsc
.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4