Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

Jason Mulligan edited this page · 76 revisions
Clone this wiki locally

Welcome to the turtle.io wiki!

turtle.io is an easy to use web server for a node.js environment. Why have a complicated stack if you can have a super fast, async web server?

Examples

Virtual hosts

Virtual host keys are the hostname, and the value is the directory relative to "root". You must set the default value, otherwise turtle.io will not be able to handle all routes.

var turtle = require("turtle.io"),
    config, server;

config = {
    default : "mycompany.com",
    uid     : 100,
    port    : 80,
    root    : "/var/www",
    pages   : "custom",
    vhosts  : {
        "mycompany.com"      : "mycompany.com",
        "www.mycompany.com"  : "mycompany.com",
        "blog.mycompany.com" : "blog.mycompany.com"
    }
}

server = new turtle();
server.start(config);

Proxy routes

The /api route acts as a proxy to another service. This example also utilizes a config.json file local to the server script, for easy DevOps management.

var config    = require("./config.json"),
    turtle_io = require("turtle.io"),
    server    = new turtle_io();

// Setting proxy routes
server.proxy("/github", "https://api.github.com"[, "hostname"]);

server.start(config);

Handling Uploads

The request object which is passed to every route handler as the second argument, will have a body property with the payload from the Client. It will not be coerced to another format, so if you expect JSON, you'll have to JSON.parse() it yourself (for now). This only applies to PATCH, POST, & PUT requests.

Configuration

Configuration values can be set by editing config.json in the turtle.io directory, or by passing an Object to start().

cache

Number (1000)

Size of LRU cache for Etag validation.

default

String

[Required] Default hostname to handle requests which are not specified within vhosts; must be a valid entry within vhosts.

headers

Object

Response headers. CORS is enabled by default.

index

Array

Files to look for when accessing a directory resource.

lag

Number (70)

Milliseconds to configure toobusy.maxLag().

logs

Object

Logging configuration.

logs.format

String (%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\")

Common Log Format string of tokens, defaulting to standard Virtual Host format.

logs.level

String ("info")

Minimum Common Log Level which is emitted to stdout.

logs.stdout

Boolean (true)

Override & disable stdout emitting by setting to false.

logs.syslog

Boolean (true)

Override & disable syslog emitting by setting to false.

logs.time

String (D/MMM/YYYY:HH:mm:ss ZZ)

Format for the date/time portion of a log message.

pages

String (null)

Directory relative to root which has files named for HTTP status codes, to be served upon error, e.g. 404.htm.

port

Number (8000)

Port the server will listen on.

proxy

Object

Proxy configuration.

proxy.rewrite

Array

Content-Type header values to apply URL rewrites to.

root

String (./sites)

Relative path to the web root directory.

ssl.cert

Object

[Optional] SSL certificate

ssl.key

Object

[Optional] SSL certificate key/pem

uid

Number (null)

[Optional] UID the server runs as.

vhosts

Object

[Required] Virtual hosts the server will respond for, key is the hostname & value is the directory relative to root.

API

Please visit api.turtle.io

License

Copyright (c) 2013 Jason Mulligan
Licensed under the BSD-3 license.

Something went wrong with that request. Please try again.