Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
|
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
function Server(port, child) {
|
||||
this.port = port;
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
Server.prototype = {
|
||||
/**
|
||||
* Formats given input with localhost and port.
|
||||
*
|
||||
* @param {String} path part of url.
|
||||
* @return {String} url of location.
|
||||
*/
|
||||
url: function(path) {
|
||||
return 'http://localhost:' + this.port + '/' + path;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends signal to stop child process and stop server.
|
||||
*/
|
||||
stop: function() {
|
||||
this.child.send('stop');
|
||||
this.child.kill();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Spawn the child process where the http server lives.
|
||||
*
|
||||
* @param {Function} callback [Error err, Server server].
|
||||
*/
|
||||
function create(callback) {
|
||||
var fork = require('child_process').fork;
|
||||
var child = fork(__dirname + '/server_child.js');
|
||||
|
||||
// wait for start message ['start', PORT_NUMBER].
|
||||
child.on('message', function(data) {
|
||||
if (Array.isArray(data) && data[0] === 'start') {
|
||||
callback(null, new Server(data[1], child));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Server.create = create;
|
||||
|
||||
module.exports = Server;
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
var Static = require('node-static'),
|
||||
http = require('http'),
|
||||
emptyPort = require('empty-port');
|
||||
|
||||
var Server = {
|
||||
/**
|
||||
* Http server running in this process.
|
||||
*/
|
||||
http: null,
|
||||
|
||||
stop: function() {
|
||||
if (this.http) {
|
||||
this.http.close();
|
||||
}
|
||||
},
|
||||
|
||||
start: function(port) {
|
||||
// using node-static for now we can do fancy stuff in the future.
|
||||
var file = new Static.Server(__dirname + '/../fixtures/');
|
||||
this.http = http.createServer(function(req, res) {
|
||||
req.addListener('end', function() {
|
||||
// hand off request to node-static
|
||||
file.serve(req, res);
|
||||
}).resume();
|
||||
}).listen(port);
|
||||
}
|
||||
};
|
||||
|
||||
// figure out which port we are on
|
||||
emptyPort({}, function(err, port) {
|
||||
Server.start(port);
|
||||
process.send(['start', port]);
|
||||
});
|
||||
|
||||
// handle process messages
|
||||
process.on('message', function(data) {
|
||||
switch (data) {
|
||||
case 'stop':
|
||||
Server.stop();
|
||||
break;
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue