Home
  • About
  • Legal information
  • English
  • Russian

LeNode

is a Node JS based minimalistic web-server
with easy-to-create site building system

Features
- Easy setup
You can setup your server by:
Creating .indexes files by JSON format in any domain-directory like this:
{
    "index_own.js" : {
        "executable" : true,
        "charset" : "utf8"
    },
    "second_own_index.html" : {
        "charset" : "win1251"
    },
    "third_own_index.ext" : {}
}
Editing .hosts.js file:
module.exports = [
    //host must be described as string or regExp without flags
    [ /(localhost|192\.168\.\d{1,3}\.\d{1,3}|127\.0\.0\.1)/, '/localhost' ], // any request to "local" address will be redirected to /localhost folder
    [ /.*/, '/not-existent-host' ],
]
And, of course, keep eye on .settings.js file:
var __appDir = (a=>{a.pop();return a.join('/')})(process.mainModule.filename.split('/')),
    polymorph = require(__appDir + '/.modules/polymorph');
module.exports = {
    defaultIndex : /* Default single index file settings */{
        executable : false, // do execute?,
        charset : 'utf8', // file encoding
    },
    defaultIndexes : /* Indexes list by default. WARNING!!! All indexes inheriting parents! */ {
        'index.js' : {
            executable : true,
        },
        'index2.html' : {},
    },
    advancedLogging : false,
    serverTimeout : 10000, // 10 secs. to autoclose connection
    mimeTypes : [ // Description of non-executable files mime types (any executable will be returned as text/html)
        [/.*\.js$/,     'application/javascript'], // any non-executable .js file
        [/.*\.css$/,    'text/css'],
        [/.*/,          'application/octet-stream'] // any other file
    ],
    preventImplicitTransfer : 'isFileExecutable, stats, err, url, tmpStack, indexes, retFirstIndex, i, foundIndex, pH, headersClosed, app', // List of variables to prevent implicit passing to the page (to not prevent, clear this list)
    additionalModules : {
        polymorph : polymorph.mainInterface,
    },
    enableFTP : true,
}
In any domain directory, you can route all your links in .router.js file placed in domain root:
[
    [ /.*\/\.indexes\/*$/, '/403.code' ],
    [ /^\/?\.router\.js\/*$/, '/403.code' ],
    [ '/execute', '/me.ext', true /* now /me.ext is executable but only from url /execute */],
    [ /\/*(tests\/a?sync_test\.js)\/*$/, '/$1', true /* tests files async_test.js and sync_test.js are executable from own url */],
    [ /\/*(tests\/.*\.js)\/*$/, '/$1', false /* all other .js files in /tests/ are now not executable from own url and urls with slashes at the end */],
    [ /\/*(.*\.js)\/*$/, '$1', true /* all other .js files are now executable from own url and urls with slashes at the end */],
]
You can execute any file with any extension as a JS file. Any directory will get its parent indexes if you don't overwrite them
Next, your executable pages will be automatically wrapped in page() function like this
page(
    write, // function that writes contents directly to page without buffering
    GET, // GET object (PHP analogue)
    POST, // POST object (PHP analogue)
    REQUEST, // REQUEST object (PHP analogue)
    headers, // request headers
    IP, // remote client IP
    addHeaders, // function that adds headers to queue (if you're used write(), headers will be placed no more). For setting responce code, you may use addHeaders({code:200}) (200 is default). If you will set an existing header, it will be overwrited by new
    polymorph // a function, that ables you easily to create an overflowed functions. Usage:
    /*
        // Creating function
        var func = polymorph(
            function(a,b,c){return '3 any args passed';},
            {i: String, a: Boolean},
            function(i,a){return 'Passed string and boolean';}
        );
    */
    ){
    // your code actually goes here
}
- Lightweight
On Windows 10 machine it using ~8-9 MBs of memory
- Extensible
Any changes (excluding main server file) will be applied immediately, there are no need to restart the server