Skip to content

Instantly share code, notes, and snippets.

@ottomata
Created September 20, 2016 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ottomata/b0b85d88f7f9dd0be5524adaf1e63253 to your computer and use it in GitHub Desktop.
Save ottomata/b0b85d88f7f9dd0be5524adaf1e63253 to your computer and use it in GitHub Desktop.
I sorta got this working. This expects build to be at ./src/build, and ./src to be the imply-pivot git submodule. It works as nodejs ./app.sh, but for some reason not yet via service-runner. Still working on it.
"use strict";
var debugModule = require('debug');
var http = require('http');
function createPivotServer(config) {
var debug = debugModule('pivot:www');
config = config || {};
// HACK! build/server/config.js uses process.argv directly, so we can't
// do much about that.
process.argv = process.argv.slice(0,2);
if (config.pivot_config_file) {
process.argv = process.argv.concat([
'--config',
config.pivot_config_file
]);
}
if (config.druid_host) {
process.argv = process.argv.concat([
'--druid',
config.druid_host
]);
}
if (config.port) {
process.argv = process.argv.concat([
'--port',
config.port
]);
}
console.log('config', config);
console.log('argv', process.argv);
// require config, this will examine process.argv
var pivotConfig = require('./src/build/server/config');
console.log(pivotConfig);
var app = require('./src/build/server/app');
var server = http.createServer(app);
server.on('error', function (error) {
if (error.syscall !== 'listen') {
throw error;
}
switch (error.code) {
case 'EACCES':
console.error("Port " + config_1.SERVER_SETTINGS.getPort() + " requires elevated privileges");
process.exit(1);
break;
case 'EADDRINUSE':
console.error("Port " + config_1.SERVER_SETTINGS.getPort() + " is already in use");
process.exit(1);
break;
default:
throw error;
}
});
server.on('listening', function () {
var address = server.address();
console.log("Pivot is listening on address " + address.address + " port " + address.port);
debug("Pivot is listening on address " + address.address + " port " + address.port);
});
app.set('port', config_1.SERVER_SETTINGS.getPort());
server.listen(config_1.SERVER_SETTINGS.getPort(), config_1.SERVER_SETTINGS.getServerHost());
return server;
}
// If this file is being run directly, just create the server with
// defaults and start listening.
if (require.main === module) {
createPivotServer({
druid_host: 'localhost:8082'
});
}
module.exports = function(options) {
// Pass in service config object from service runner config.yal
return createPivotServer(options.config);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment