Skip to content

Commit

Permalink
Refactor server detection for use by other programs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Robinson committed Sep 29, 2009
1 parent 7321cee commit b55bfe6
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions lib/jackup.js
Expand Up @@ -115,24 +115,7 @@ exports.main = function main(args) {
if (typeof app !== "function")
throw new Error("JSGI application must be a function, is: " + app);

var server = options.server;
if (!server)
{
if (system.env["PHP_FCGI_CHILDREN"] !== undefined)
server = "fastcgi";
else if (system.engine === "rhino")
server = "simple";
else if (system.engine === "k7")
server = "shttpd";
else if (system.engine === "v8cgi")
server = "v8cgi";
else if (system.engine === "xulrunner")
server = "mozhttpd";
else if (system.engine === "jsc")
server = "jill";
else
throw new Error("Unknown engine " + system.engine + ". Specify a server with the \"-s\" option.");
}
var server = options.server || exports.detectHandler();

// Load the required handler.
var handler = null;
Expand All @@ -148,6 +131,27 @@ exports.main = function main(args) {
handler.run(app, options);
};

exports.detectHandler = function() {
var server = null;

if (system.env["PHP_FCGI_CHILDREN"] !== undefined)
server = "fastcgi";
else if (system.engine === "rhino")
server = "simple";
else if (system.engine === "k7")
server = "shttpd";
else if (system.engine === "v8cgi")
server = "v8cgi";
else if (system.engine === "xulrunner")
server = "mozhttpd";
else if (system.engine === "jsc")
server = "jill";
else
throw new Error("Unknown engine " + system.engine + ". Specify a server with the \"-s\" option.");

return server;
};

if (module.id == require.main)
exports.main(system.args);

0 comments on commit b55bfe6

Please sign in to comment.