Skip to content

Commit

Permalink
new pattern for campaign: v3-social-pressure
Browse files Browse the repository at this point in the history
  • Loading branch information
vecna committed Jun 17, 2018
1 parent 2443b42 commit b74e7a8
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 191 deletions.
92 changes: 92 additions & 0 deletions bin/v3-social-pressure.js
@@ -0,0 +1,92 @@
#!/usr/bin/env nodejs
var express = require('express');
var app = express();
var server = require('http').Server(app);
var Promise = require('bluebird');
var _ = require('lodash');
var moment = require('moment');
var debug = require('debug')('v2-social-pressure');
var nconf = require('nconf');
var machetils = require('../lib/machetils');

var defaultCfg = "config/v3-social-pressure.json";
nconf.argv().env();
var cfgFile = nconf.get('config') || defaultCfg;

nconf.argv()
.env()
.file('config', cfgFile);

var campaign = nconf.get('campaign');
if(_.isUndefined(campaign) || campaign === "overwritewithenvorcommandline")
machetils.fatalError("MISSING: campaign environment variable");

var campaignc = 'campaigns/' + campaign + "/config/" + campaign + ".json";
debug("Loading as campaign config: %s", campaignc);

nconf.argv()
.env()
.file('campaign', campaignc)
.file('config', cfgFile);

/* initialize libraries and inclusion only if the `campaign` variable set */
var routes = require('../routes/_v3socialpressure');
var dispatchPromise = require('../lib/dispatchPromise');

/* test, is "port" is not found, then campaign is not found too */
if(!nconf.get('port')) {
console.error("Probabily the campaign suggested has not the settings file");
console.error("campaigns/"+ campaign + ".json is required");
console.error("check in campaigns/README.md the format");
machetils.fatalError("missing configuration (port)");
}


/* everything begin here, welcome */
server.listen(nconf.get('port'), nconf.get('interface') );
console.log( "http://" + nconf.get('interface') + ':' + nconf.get('port') + " listening");

/* ------------------------------------------------------------ */
var paths = process.env.PWD.split('/');
paths.push('dist');
var distPath = paths.join('/');

app.get('/favicon.ico', function(req, res) {
res.sendFile(distPath + '/favicon.ico');
});
app.get('/robots.txt', function(req, res) {
res.sendFile(distPath + '/robots.txt');
});

app.use('/css', express.static(distPath + '/css'));
app.use('/lib', express.static(distPath + '/lib'));
app.use('/fonts', express.static(distPath + '/fonts'));
app.use('/images', express.static(distPath + '/images'));

/* development: the local JS are pick w/out "npm run build" every time */
if(nconf.get('development') === 'true') {
var scriptPath = '/../sections/webscripts';
console.log("ઉ DEVELOPMENT = serving JS from", distPath + scriptPath);
app.use('/js/local', express.static(distPath + scriptPath));
} else {
app.use('/js/local', express.static(distPath + '/js/local'));
}
app.use('/js/vendor', express.static(distPath + '/js/vendor'));
app.use('/campaign', express.static(distPath + '/../campaigns/' + campaign + '/web-accessible'));

app.get('/api/v:version/tasks/:cname', function(req, res) {
return dispatchPromise('getCampaignPromises', routes, req, res);
});

/* This render the monoPage campaign */
var monoPage = require('../campaigns/' + campaign + '/page/controller.js');
app.get('/', function(req, res) {
debugger;
return new Promise
.resolve(monoPage(req))
.then(function(httpresult) {
debug("serving /");
debugger;
res.send(httpresult.text)
});
});
4 changes: 4 additions & 0 deletions config/campaigns.json
Expand Up @@ -17,6 +17,10 @@
"name": "kzbrg",
"csv": "kzbrg/kzbrg.csv"
} ],
"degov": [ {
"name": "degov",
"csv": "degov/degov.csv"
} ],
"social-media": [ {
"name": "social-media",
"csv": "/dev/null"
Expand Down
34 changes: 34 additions & 0 deletions config/v3-social-pressure.json
@@ -0,0 +1,34 @@
{
"name": "v3-social-pressure",
"campaign": "overwritewithenvorcommandline",

"schema": {
"accesses": "accesses",
"statistics": "statistics",
"promises": "promises2",
"surface": "surface",
"evidences": "evidences",
"details": "details",
"summary": "summary",
"judgment": "judgment",
"sites": "sites"
},
"mongodb": "mongodb://localhost/ivl",
"watch": [
"bin/v3-social-pressure.js",
"sections/webscripts/*.js",
"campaigns/*",
"routes/*.js",
"lib/*.js",
"dist/**",
"config/*.json"
],
"verbose": true,
"exitcrash": false,
"env": {
"DEBUG": "*,-ffi:*,-ref*,-send,-express:*"
},
"ext": "js css json pug"
}


7 changes: 0 additions & 7 deletions lib/dispatchPromise.js
Expand Up @@ -62,13 +62,6 @@ function dispatchPromise(name, routes, req, res) {
/* is a promise, the actual return value don't matter */
return various.accessLog(name, req, httpresult);
});
/*
.catch(function(error) {
debug("%s Trigger an Exception %s: %s",
req.randomUnicode, name, error);
return returnHTTPError(req, res, name, "Exception");
});
*/
};

module.exports = dispatchPromise;
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -12,6 +12,7 @@
"storyteller": "nodemon --config config/storyteller.json bin/storyteller",
"social-pressure": "nodemon --config config/social-pressure.json bin/social-pressure",
"v2-social-pressure": "nodemon --config config/v2-social-pressure.json bin/v2-social-pressure",
"v3-social-pressure": "nodemon --config config/v3-social-pressure.json bin/v3-social-pressure",
"vigile": "nodemon --config config/vigile.json bin/vigile",
"exposer": "DEBUG=*:-express:* node bin/exposer",
"badger": "type=badger DEBUG=*,-lib:urlutils,-lib:cmdspawn node bin/chopsticks",
Expand Down
3 changes: 1 addition & 2 deletions routes/_storyteller.js
Expand Up @@ -15,13 +15,12 @@ module.exports = {
getCSV: require('./getCSV'),
activeTasks: require('./activeTasks'),
getRaw: require('./getRaw'),
getTableauJSON: require('./getTableauJSON'),
getTableauJSON: require('./getTableauJSON'),
getCheckURL: require('./getCheckURL'),
getMixed: require('./getMixed'),
getJudgment: require('./getJudgment'),
getSiteInfo: require('./getSiteInfo'),

getKzbrg: require('./getKzbrg'),
serveCampaign: require('./serveCampaign'),
serveSite: require('./serveSite'),

Expand Down
76 changes: 0 additions & 76 deletions routes/getKzbrg.js

This file was deleted.

106 changes: 0 additions & 106 deletions sections/kzbrg.pug

This file was deleted.

0 comments on commit b74e7a8

Please sign in to comment.