statikk
v3.1.0
Published
Simple, secure static file server – serve any directory over HTTP
Maintainers
Readme
Statikk 
A simple and secure server for static files.
- Pithy flags for CORS and Cross-origin isolation.
- Two smart security defaults:
- Your
.gitfiles are not exposed. (Whereas ALL other simple http servers do expose this security concern (exceptserve)) - The server isn't accessible outside of
localhost. Other folks on your network won't be able to browse it via your internal IP.
- Your
- If you don't specify a port, it'll be deterministically generated based on your working directory. :tada:
Command line usage
$ npm install -g statikk
$ cd ~/Sites/fidgetspin.xyz
$ statikk --cors --open
🤓 http://localhost:10810 statikk serving locally: ~/Sites/fidgetspin.xyzCommand line options
--port NNNN: custom port. If not specified, it'll use a port automagically based onprocess.cwd(). (So different projects use different ports!)--open: Open the hosted URL in your default browser. (Only supported on Mac OS!)--cors: Add CORS headers--coi: Add cross-origin isolation headers (more)--jsprof: Adddocument-policy: js-profilingheader (for js self-profiling api)--csp VAL: Add a Content-Security-Policy header with valueVAL
This weakens security:
--expose: expose server to hosts other thanlocalhost.
All non-port options default to false (except --csp which is undefined by default).
Examples
// Start server at http://localhost:9000 serving ./
$ statikk --port 9000
// Start server at http://localhost:60384 (perhaps) serving ~/Sites/project
$ statikk ~/Sites/project
// Start server at a deterministically-chosen port based on the working directory, and open the browser
$ statikk --openProgrammatic ESM usage
import statikk from 'statikk';
const { app, server, options, url } = await statikk({
root: './public', // Defaults to process.cwd()
port: 3000, // Defaults to a deterministic port based on root
cors: true,
coi: true,
csp: "default-src 'self'",
open: true, // Open browser on macOS
});
// To stop the server:
// server.close();Options
statikk accepts an options object:
root: The directory to serve. Defaults toprocess.cwd().port: The port to listen on. If not specified or0, it will use a port based onroot.cors: Boolean, add CORS headers. Defaults tofalse.coi: Boolean, add Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers. Defaults tofalse.jsprof: Boolean, adddocument-policy: js-profilingheader. Defaults tofalse.csp: String, value forContent-Security-Policyheader. Defaults toundefined.open: Boolean, open browser on server start (only supported on macOS). Defaults tofalse.compress: Boolean, enable gzip compression. Defaults totrue.expose: Boolean, allow access from other hosts on the network (listens on0.0.0.0instead oflocalhost). Defaults tofalse.
Additionally, any options accepted by serve-static can be passed, such as maxAge, dotfiles, etc.
History
This project is a fork of...
- https://github.com/boardman/statik which is a fork of
- https://github.com/johnkelly/statik which is a fork of
- https://github.com/hongymagic/statik (the OG
statikon NPM), but unmaintained since 2013.
The original project doesn't correctly exclude all hidden files, which is why I've forked and republished. ~paul irish. june 2017.
