New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

simplicity

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplicity

A server that let you handle GET and POST HTTP requests with simplicity.

latest
Source
npmnpm
Version
1.1.3
Version published
Maintainers
1
Created
Source

Simplicity

A server that let you handle GET and POST HTTP requests with simplicity.

How to Install

npm install simplicity

Example

var server = require("simplicity");

server.start_server(function (data, response)
{
    response.end("You requested " + data.uri);
});

Usage

// First, load Simplicity.
var server = require("simplicity");

This will create an object with two function: start_server() and htmlentities().

start_server([config,] callback)

config is an optional object describing how Simplicity should work.

{
    password:           (string)  The password used to authenticate the user
    port:               (number)  The port number to listen to                                          (default: 8888)
    post_limit          (number)  How many bytes to receive of POST data before dropping the connection (default: 2097152 (2mb))
    protect:            (boolean) Whether or not to require basic access authentication                 (default: FALSE)
    redirect:           (array)   An array of URLs to be intercepted and sent to the callback           (default: ["/"])
    redirect_on_errors: (boolean) Whether or not to send 404 errors to the callback                     (default: TRUE)
    root_path:          (string)  The www root directory                                                (default: current working directory)
    timeout:            (number)  How long to wait before dropping the connection if it hasn't finished (default: 60000 (1 min))
    username:           (string)  The authenticated user
}

callback(data, response) will be called by Simplicity when a request comes in (that is not for a static resource) and has two parameters: data and response.

data

{
    cookies:  Cookies sent in the request
    filename: The location on the server for the request
    get:      The GET data (as an object)
    headers:  The HTTP headers from the request
    post:     The POST data (as an object)
    uri:      The URI being requested
}

reponse

{
    end:        function ([data[, encoding]]) // Close the request (and optionally write a message)
    send_404:   function ()                   // Send a 404 error and close the request
    write:      function (data[, encoding])   // Write data back to the client
    write_head: function (code[, headers])    // Write HTTP headers back to the client
}

htmlentities(string)

Encode a string so that it will display as text not HTML.

For example:

server.htmlentities("<script>"); // Returns: "&lt;script&gt;"

License

MIT

FAQs

Package last updated on 21 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts