Skip to content
Snippets Groups Projects
Commit bee8cb50 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

a little wrapper file to run the implementation provider/secondary thingy...

a little wrapper file to run the implementation provider/secondary thingy standalone outside of the test harness
parent fb240154
No related branches found
No related tags found
No related merge requests found
var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
connect = require("connect");
var PRIMARY_HOST = "127.0.0.1";
var PRIMARY_PORT = 62700;
var handler = require("./run.js");
function subHostNames(data) {
const hostsubmap = {
"authority.mozilla.org": "eyedee.me"
};
for (var k in hostsubmap) {
var from = k;
var to = hostsubmap[k];
data = data.replace(new RegExp(from, 'g'), to);
}
return data;
}
function serveFile(filename, response) {
path.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not Found");
response.end();
return;
}
fs.readFile(filename, "binary", function(err, data) {
if(err) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(err + "\n");
response.end();
return;
}
var exts = {
".js": "text/javascript",
".css": "text/css",
".html": "text/html",
".webapp": "application/x-web-app-manifest+json",
".png": "image/png",
".ico": "image/x-icon"
};
var ext = path.extname(filename);
var mimeType = exts[ext] || "application/octet-stream";
data = subHostNames(data);
response.writeHead(200, {"Content-Type": mimeType});
response.write(data, "binary");
response.end();
});
});
}
var server = connect.createServer().use(connect.favicon())
.use(connect.logger({format: ":status :method :remote-addr :response-time :url"}));
// let the specific server interact directly with the connect server to register their middleware
if (handler.setup) handler.setup(server);
server.use(function(req, resp, next) {
handler.handler(req, resp, serveFile, subHostNames);
});
server.listen(PRIMARY_PORT, PRIMARY_HOST);
console.log("bound to " + PRIMARY_HOST + ":" + PRIMARY_PORT);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment