UNPKG

openhim-core

Version:

The OpenHIM core application that provides logging and routing of http requests

51 lines (35 loc) 1.16 kB
var Channel, Q, SDC, application, config, domain, logger, os, sdc, statsdServer; Q = require("q"); Channel = require("../model/channels").Channel; logger = require("winston"); config = require('../config/config'); statsdServer = config.get('statsd'); application = config.get('application'); SDC = require('statsd-client'); os = require('os'); domain = (os.hostname()) + "." + application.name + ".appMetrics"; sdc = new SDC(statsdServer); exports.authoriseUser = function(ctx, done) { return Channel.findOne({ _id: ctx.request.header['channel-id'] }, function(err, channel) { ctx.authorisedChannel = channel; return done(null, channel); }); }; /* * Koa middleware for bypassing authorisation for polling */ exports.koaMiddleware = function*(next) { var authoriseUser, startTime; if (statsdServer.enabled) { startTime = new Date(); } authoriseUser = Q.denodeify(exports.authoriseUser); (yield authoriseUser(this)); if (statsdServer.enabled) { sdc.timing(domain + ".pollingBypassAuthorisationMiddleware", startTime); } return (yield next); }; //# sourceMappingURL=pollingBypassAuthorisation.js.map