stack.static

0.0.3 • Public • Published

Coffee-Resque

Static file middleware for Stack. It supports HTTP Conditional GET with ETags and file modification dates, and Range requests.

USAGE

You can place the middleware directly in a Stack server:

var Static = require('stack.static')
http.createServer(require('stack')(
  Static(rootPath, {"default": "index.html"}),
  //...
)).listen(8080);

You can serve a file manually without using Stack too:

var Static = require('stack.static')
http.createServer(function(req, res) {
  Static.serve(rootPath + req.url, req, res, 
    function(err) {
      if(err) { ... 404! ... }
    })
})

You can probably replace the serve() function with your own implementation if you want to serve files from somewhere else (S3, GridFS, whatevs).

You can set default headers that get set on every response:

var Static = require('stack.static')
Static.defaultHeaders['cache-control'] = 'public'

You can override the global default handlers in each Static handler too:

var Static = require('stack.static')
http.createServer(require('stack')(
  Static(rootPath, 
    { "default": "index.html"
    , "headers": 
      { "cache-control": "public"
      }
    }
  ),
)).listen(8080);

INSTALL

npm install simple-mime
npm install stack.static

Development

All code is written in Coffee Script and converted to javascript as it's published to npm.

For normal development, all you need to be concerned about is testing:

$ make test

If you need to generate javascript for production purposes and don't want to use npm packages, you can use:

$ make generate-js
$ make remove-js

You can also have coffeescript watch the src directory and generate javascript files as they're updated.

$ make dev

TODO

Readme

Keywords

none

Package Sidebar

Install

npm i stack.static

Weekly Downloads

26

Version

0.0.3

License

none

Last publish

Collaborators

  • technoweenie