Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/query from file #42

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,20 @@ const config = require('../config/general.json');
const start = async () => {
const PORT = process.env.PORT || 3000;

logger.info('Apollon initializing');

// Initialisation of the connectors
for (let connectorName in connectors) {
connectors[connectorName] = connectors[connectorName].apply({ logger, config });
}
let childLogger = logger.child({ scope: 'userland' });

logger.trace('Waiting for connectors to initialize');
// Waiting for them to be ready
for (let connectorName in connectors) {
connectors[connectorName] = await connectors[connectorName];
childLogger.domain = function(obj, potMessage){
const domain = {scope: "domain"};
if(potMessage){
childLogger.info(Object.assign(obj,domain), potMessage)
} else {
childLogger.info(domain, obj);
}
}
logger.trace('Connectors initialized');

const app = express();
logger.trace('Express app started');

let childLogger = logger.child({ scope: 'userland' });

// childLogger.domain = function(...args){
// childLogger.
// }

const context = {
PORT,
ENDPOINT: config.endpoint || '/',
Expand All @@ -69,6 +60,20 @@ const start = async () => {
};
logger.trace('Created context object');

logger.info('Apollon initializing');

// Initialisation of the connectors
for (let connectorName in connectors) {
connectors[connectorName] = connectors[connectorName].apply(context);
}

logger.trace('Waiting for connectors to initialize');
// Waiting for them to be ready
for (let connectorName in connectors) {
connectors[connectorName] = await connectors[connectorName];
}
logger.trace('Connectors initialized');

let authenticateMid = authenticate(context);
logger.trace('Authentication middleware generated');

Expand Down
19 changes: 19 additions & 0 deletions src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module.exports = async function tests(context){
const requireDir = require("require-dir");
const path = require("path");
const jasmine = require('jasmine-node');
const {promisify} = require('util');
const fs = require('fs');

const hook = require("../other/report");
const childLogger = context.logger.child({scope: "tests"});
Expand Down Expand Up @@ -37,6 +39,23 @@ module.exports = async function tests(context){
return getClient;
};
}
if(!client.queryFromFile){
client.queryFromFile = function(path){
let query = "";
let q = promisify(fs.readFile)(path, 'utf8')
.then(file => query = file);
;
let queryFromFileRoot = {
send(){
return q.then(_ => client.query(query, {}));
},
injectAndSend(data){
return q.then(_ => client.query(query, data));
}
}
return queryFromFileRoot;
}
}
return client;
}

Expand Down