<commit_before>var request = require('superagent');
var bodyParser = require('body-parser');
var _ = require('lodash');

var q = require('./config/kue');
var geogw = require('./geogw');

var organizations = require('./controllers/organizations');
var producers = require('./controllers/producers');
var datasets = require('./controllers/datasets');

function ensureLoggedIn(req, res, next) {
    if (!req.user) return res.sendStatus(401);
    next();
}

function isAdmin(req, res, next) {
    if (!req.user.isAdmin) return res.sendStatus(403);
    next();
}

module.exports = function (app) {

    app.use(bodyParser.json());

    app.use('/api', function (req, res, next) {
        if (!req.user) return res.sendStatus(401);
        next();
    });

    app.get('/api/me', function (req, res) {
        res.send(req.user);
    });

    app.get('/api/catalogs', function (req, res, next) {
        request
            .get(process.env.GEOGW_URL + '/api/catalogs')
            .end(function (err, resp) {
                if (err) return next(err);
                if (resp.error) return next(new Error('Server returned status %d', resp.status));
                res.send(resp.body);
            });
    });

    app.get('/api/catalogs/:catalogId/producers', function (req, res, next) {
        var query = {
            limit: 1,
            opendata: 'yes',
            availability: 'true'<commit_msg>Fix producers list API call<commit_after>var request = require('superagent');
var bodyParser = require('body-parser');
var _ = require('lodash');

var q = require('./config/kue');
var geogw = require('./geogw');

var organizations = require('./controllers/organizations');
var producers = require('./controllers/producers');
var datasets = require('./controllers/datasets');

function ensureLoggedIn(req, res, next) {
    if (!req.user) return res.sendStatus(401);
    next();
}

function isAdmin(req, res, next) {
    if (!req.user.isAdmin) return res.sendStatus(403);
    next();
}

module.exports = function (app) {

    app.use(bodyParser.json());

    app.use('/api', function (req, res, next) {
        if (!req.user) return res.sendStatus(401);
        next();
    });

    app.get('/api/me', function (req, res) {
        res.send(req.user);
    });

    app.get('/api/catalogs', function (req, res, next) {
        request
            .get(process.env.GEOGW_URL + '/api/catalogs')
            .end(function (err, resp) {
                if (err) return next(err);
                if (resp.error) return next(new Error('Server returned status %d', resp.status));
                res.send(resp.body);
            });
    });

    app.get('/api/catalogs/:catalogId/producers', function (req, res, next) {
        var query = {
            limit: 1,
            opendata: 'yes',
            availability: 'yes'
{'fraction_non_alphanumeric': 0.1703940362087327, 'fraction_numerical': 0.007099751508697196, 'mean_word_length': 2.571609632446134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4374770', 'n_tokens_mistral': 891, 'n_tokens_neox': 856, 'n_words': 199}