Skip to content
tiny library to host static files
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
public
LICENCE
README.md
StaticHoster.js
package.json
sample.js

README.md

statichoster

[Node.js] hosting static files in a public directory

Installation

git clone git://github.com/shinout/statichoster.git

OR

npm install statichoster

Usage

var http = require("http");
var StaticHoster = require("./StaticHoster");
var sh = new StaticHoster(__dirname + "/public", {
  html: "text/html"
});

var server = http.createServer(function(req, res) {
  sh.host(req, res, function(err, result) {
    // if error
    if (err) console.log(err);

    // if statichoster write something to response
    if (result) return;

    // if statichoster do nothing
    res.writeHead(200, {'Content-Type' : 'text/plain' });
    res.end("other types of request\n");
  });
});

server.listen(1192);

set public directory

// the first argument of constructor
var sh = new StaticHoster(__dirname + "/public");

set filetypes

// the first argument of constructor
var sh = new StaticHoster(__dirname + "/public", {
  html : "text/plain", // extension name => mime-type

  tiff : ["image/tiff, images] // extension name => [ mime-type, name of the subdirectory ]
});

original filetypes

// extension name => [mime-type, name of the subdirectory]
css       : ['text/css', 'css'],
js        : ['text/javascript', 'js'],
png       : ['image/png', 'images'],
jpg       : ['image/jpeg', 'images'],
gif       : ['image/gif', 'images'],
ico       : ['image/vnd.microsoft.icon', ''],
manifest  : ['text/cache-manifest', '']
Something went wrong with that request. Please try again.