Tonto.js: Apache Config File Generator
_____ ___ _ _ _____ ___|_ _/ _ \| \| |_ _/ _ \| || (_) | .` | | || (_) ||_| \___/|_|\_| |_| \___/.JSAPACHE CONFIG FILE GENERATOR
Additionally, Tonto is easily configured at instantiation to support any custom directive that you may have, (such as 3rd-party mod directives like 'PassengerRoot').
This library is named after the Tonto (Dilzhę́’é) people, who are one of the Western Apache groups in North America.
Long ago, their enemies called them "foolish", "wild", "crazy", and "those who you don't understand" for speaking and doing things differently than their neighbors. Today, they are known throughout the art communities for their superior fine crafts.
Use NPM to install the
tonto package into your node.js project:
$ npm install tonto --save
1. Each instance of Tonto is a version-specific apache config document object that you add directives to by calling it's directive functions:
var tonto = '2.4';
2. There are solo directive functions that take a single value argument, and block directive functions which take a sub-directive setter object as the second argument:
tontovirtualHost'*:80'// Here, you can call any directive function directly on subDirectiveDocument, and it will be added as a sub-directive.subDirectiveDocumentserverName'somesite.com';;
3. When the document object has all directives added to it, you can render the document to string by calling:
4. All directives are chainable:
var renderedDocument = tontoloadModule'some_module /some/path/to/module.so'serverSignature'Off'traceEnable'Off'render;
Tonto.js comes with built-in support for all native (and native mod) directives in versions 2.4, 2.2, and 2.0. Additionally, you can specify any number of extra directives.
You specify which version you want to use during instantiation of the constructor:
var twoFour = Tonto'2.4';ObjectkeystwoFourlength; // 594var twoTwo = Tonto'2.2';ObjectkeystwoTwolength; // 419var twoZero = Tonto'2.0';ObjectkeystwoZerolength; // 364
Whereas Apache directives are typed in TitleCase, tonto converts each of the directives into camelBackCase named functions.
LoadModuleis added to the document with:
SSLCertificateKeyFileis added to the document with:
VirtualHostis added to the document with:
Block directives require a function as the second argument. This function has one argument itself, which is a clean sub-document. You can call any directive from the main document on a sub-document.
Here is an example of a sub-directive setter defined as a named function:
This example will render:
<VirtualHost *:80>ServerName somesite.com</VirtualHost>
If you are using a 3rd party mod that provides custom directives, there is an easy way to extend tonto.js with custom functions for this purpose:
tontoextend'CustomDirective''<CustomBlock>';tontocustomDirective'some value'; // Solo directivetontocustomBlock'some value'// Because CustomBlock is surrounded in < and >, it is processed as a block directive;