turtle.io is very easy to get up and running! All you need to do is install it, and tell it what directory holds your web sites, & which hostnames to answer for.
You can also create complex web applications, with a familiar API.
- Install the module with:
npm install turtle.io
- Create a script to load & start a server. You could use
sample.js
in the turtle.io directory (./node_modules/turtle.io) as a template, or see the examples below - [Optional] You can override defaults by passing the factory an Object
The following examples assume you've installed turtle.io into /opt/turtleio
, if this is not the case you need to edit the applicable file to correct the path.
Use the provided upstart recipe: sudo sh -c 'cp node_modules/turtle.io/turtleio.conf /etc/init; initctl reload-configuration; service turtleio start;'
Use the provided systemd service: sudo sh -c 'cp node_modules/turtle.io/turtleio.service /etc/systemd/system; systemctl enable turtleio; systemctl start turtleio;'
It runs great on Windows, but you're on your own to daemonize it!
turtle.io requires a default virtual host to be specified, because it is the failover when a request can't be routed.
Virtual host keys are the hostname, and the value is the directory relative to "root".
const turtleio = require("turtle.io");
const server = turtleio({
default: "mysite.com",
port: 80,
uid: 100,
root: "/var/www",
hosts: {
"mysite.com": "mysite.com",
"another-domain.com": "another-domain.com"
}
});
server.start();
siege
was used instead of ab
because we want to compare accurate transaction rates.
- Machine MacBook Air (Early '14) / Core i7 @ 1.7Ghz / 8GB ram / 512 flash / OS X 10.10.2
- ulimit 2560
- express 4.11.2
- turtle.io 3.2.2
- benchmark
siege -c100 -b -q -H 'Connection: Keep-Alive' -t15S localhost:$@
Hello World!
from a route (content-length: 12), no allow
header.
var express = require("express"),
app = express();
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000);
Hello World!
html file streamed from disk (content-length: 53), has accurate allow
header.
"use strict";
require("index.js")({
default: "test",
root: __dirname + "/sites",
port: 8000,
hosts: {
"test" : "test"
},
logging: {
enabled: false
}
}).start();
Transaction rates are similar.
- turtle.io
[1233.78, 1203.2, 1187.44] (1208.14 avg)
- express
[1105.85, 1124.25, 1167.57] (1132.56 avg)
The request
object 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).
Function (path, method)
Determines if a path can receive an ETag
Array
Array of paths to ignore for ETag generation
Function (state)
Updates the etag cache with new state
String
Allowed HTTP methods
Number
Request IP
Object
Parsed HTTP request
String
Parsed query string
Object
turtle.io instance
String
Virtual host handling the request.
Function (status, body)
Send an error response.
Function (url)
Send a redirection.
Function (body[, status, headers])
Send a response.
Function (body[, status, headers])
Send a response.
Configuration values can be set by passing an Object to the factory, or any time afterward.
String (0.0.0.0)
Network address to listen on.
Number (1000)
Size of LRU cache for Etag validation.
Boolean (true)
Handle unterminated requests.
Boolean (true)
Compress responses when supported.
String
[Required] Default hostname to handle requests which are not specified within vhosts; must be a valid entry within vhosts.
Object
ETag middleware configuration.
To enable state propagation set notify
to true
, and when receiving new state pass to etags.update()
.
{
notify: true,
ignore: [], // Array of paths to ignore
onchange: (eventName, serializedCache) => {
... // serializedCache needs to be passed to other instances `etags.update()`
},
update: serializedCache => {
... // Override if you want to do more than set new state
}
}
Object
Response headers. CORS is enabled by default.
Object
[Required] Virtual hosts the server will respond for, key
is the hostname & value
is the directory relative to root
.
Array
Files to look for when accessing a directory resource.
Number (2)
Default "pretty" ident size
Object
Logging configuration.
Boolean (true)
Override & disable stdout
emitting by setting to false
.
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.
String ("info")
Minimum Common Log Level which is emitted to stdout
.
String (D/MMM/YYYY:HH:mm:ss ZZ)
Format for the date/time portion of a log message.
Number (1048576)
Maximum request body size; when exceeded a 429 is sent.
Number (8000)
Port the server will listen on.
String ("")
Relative path to the web root directory.
Number (625)
Seed for hashing of middleware with MurmurHash3.
String
[Optional] SSL certificate file path
String
[Optional] SSL certificate key/pem file path
String
[Optional] SSL certificate pfx file path
Number (null)
[Optional] UID the server runs as.
Copyright (c) 2017 Jason Mulligan Licensed under the BSD-3 license.