Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Static HTTP server built on node.js
branch: master
Failed to load latest commit information.
lib Allow requests to files with non-ascii characters
tests Allow requests to files with non-ascii characters
.gitignore ignore vims .swp files
LICENSE licensed all code under MIT
README.markdown older node.js versions dont have sys.pump
TODO
autotest.watchr simplify watch script by removing interrupt catcher
demo.sjs
package.json older node.js versions dont have sys.pump
runtests.js Shiny new test suite! (ported tests to nodeunit)
server.js show detailed error when you cant find settings.json
settings-sample.json Add demo server-side JS script

README.markdown

Antinode is a simple static file webserver built on node.js.

Usage

Run it from the command line.

$ node server.js [settings.json]

Requires Node.JS v0.1.100 or greater. If you want to bind to a port under 1024, you'll need to run node with special privileges.

Configuration

Configuration is through a JSON text file, by default the settings.json in the same folder as server.js.

Example settings file:

{
    "port" : 8080,
    "hosts" : {
        "subdomain1.example.com" : { 
            "root" : "/www/subdomain1/"
        },
        "subdomain2.example.com" : {
            "root" : "/www/subdomain2/"
        }
        },
    "default_host" : {
        "root" : "/www/default/"
    }
}

This server listens on port 8080 for HTTP requests. If it gets a request for Host: subdomain1.example.com the site will serve /www/subdomain1/, and similarly requests for Host: subdomain2.example.com will respond with the files from /www/subdomain2. If the Host header does not match either, or is not given, antinode will serve files from /www/default.

Explanation of properties:

  • port - the port to listen for HTTP connections on. default: 8080
  • hosts - an object with one property name per virtual host address, with the value of a 'virtual host' object to
  • default_host - the 'virtual host' object to default to if no other virtual hosts match, or the HTTP Host header is not given

'virtual host object' - has a property root giving the directory to serve web requests from

This serves up all the files in /var/www listening to HTTP requests on port 8080. E.g. an HTTP request for /styles/site.css will will look for the file /var/www/styles/site.css

Features

  • HTTP Content-Type header detection from file extension
  • HTTP Content-Length header support
  • HTTP Date header
  • HTTP Last-Modified header
  • Reads files in binary mode - so can serve images and other binary files (not just text)
  • Requests to any directory try to return directory/index.html
  • Virtual Hosts

Test Suite

To run the tests:

$ node runtests.js

Credits

Original code forked from Noah Sloan's simple logging webserver.

Something went wrong with that request. Please try again.