ssi-http-parser
v0.1.0
Published
Server Side Include(SSI) parser and ssi-http
Downloads
4
Readme
** working in progress **
A SSI-Http Server powered by NodeJS
A Server Side Include(SSI) parser and ssi-http are provided in ssi-http-parser
.
Install
npm install ssi-http-parser
Usage
The parser parse http string and return the replaced string. The parser has to be initialized.
var parser = require('ssi-parser-http').parser({
rootDomain: process.cwd(),
currentDocDir: process.cwd()
}, {
HTTP_USER_AGENT: 'www.king.agent'
});
var resHttpStr = parser.run(httpStr);
The ssi-http is based on http package except it automatically check if the incoming request ends up with .shtml
. To create server, createServer
has to be called.
var ssiHttp = require('ssi-parser-http').http
var server = ssiHttp.createServer(callback, env).listen(port);
Explicitly specify listening port in port
and static serving directory inside env
. An example:
var ssiHttp = require('ssi-parser-http').http
var server = ssiHttp.createServer(function (req, res, opt) {
// 'opt' is invoked only if the 'GET' request is for 'shtml' page. 'opt' = 'resHttpStr'.
}, {
ROOT_DIRECTORY: __dirname,
HTTP_USER_AGENT: 'www.king.agent'
}).listen(8081);
To enable DEBUG mode,
DEBUG=true node **.js
Supported SSI Directives
<!--#include attribute = value -->
<!--#echo attribute = value -->
Implementation (For Adobe reviewers)
Parsing directives is powered by regular expressions. A regexp /<!\-\-#([a-z]+)\s+([a-z]+)\s*=\s*(["'])([^]*?)\3\s+\-\->/g
is sensitive enough for any mod_include
syntax string. But this expression is not effective if multiple attributes in one directive, such as <!--#directive attribute1=... attribute2... -->
. In parser(settings, variables).run
, settings
are context(so the process know where it is) for replacing the directive. rootDomain
in settings
is context for virtual
attribute of include
directive. currentDocDir
is context for file
attribute. variables
are used for echo
directive. parser(settings, variables).run
function does directive replacement one by one until all supported format directives in document are replaced.
The ssi-http module basically extends the node http module with a wrapper function of http.createServer
and minor changes to the resulting server
instance. An ssdMiddleWare
is used to filter shtml
'GET' request. The server also maintain the environment variables, which include ROOT_DIRECTORY
the root directory in file system to serve. If it is not set, the current directory of running process will be treat as the ROOT_DIRECTORY
.