Skip to content

Documentation

micnic edited this page Nov 3, 2012 · 94 revisions
var simples = require('simples');

New simples instance

simples(port)

port: number

var server = simples(80);

or

var server = new simples(80);

Server management

Starting

.start(port, callback)

port: number

callback: function(0)

server.start(80, function () {
    // Application logic
});

Stopping

.stop(callback)

callback: function(0)

server.stop(function () {
    // Application logic
});

Routing

GET requests

.get(route, callback)

route: string

callback: function(2)

server.get('/', function (request, response) {
    // Application logic
});

POST requests

.post(route, callback)

route: string

callback: function(2)

server.post('/', function (request, response) {
    // Application logic
});

All kind of requests

.all(route, callback)

route: string

callback: function(2)

server.all('/', function (request, response) {
    // Application logic
});

Static files

.getStatic(path)

path: string

path is the local path to a folder that contains static files (for example: css and js files), this folder will serve as the root folder for the server. Only one folder should be used to server static files, if more .getStatic() methods will be called only the last will be used to serve static files. The folder with static files can contain other folders, their content will be also served.

server.getStatic('root');

Inexistent routes

.notFound(callback)

callback: function(2)

server.notFound(function (request, response) {
    // Application logic
});

WebSocket

.ws(path, config, callback)

path: string

config: object

callback: function(1)

server.ws('/', {
    messageMaxLength: 1024,
    origins: ['null'],
    protocols: ['chat']
}, function (connection) {
    // Application logic
});

Clone this wiki locally