{"size": 3455, "ext": "js", "max_stars_repo_path": "backend/routes/v1/v1.js", "max_stars_repo_name": "bcgov/metadata-curator", "max_stars_repo_stars_event_min_datetime": "2021-11-23T19:20:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-23T19:20:11.000Z", "max_issues_repo_path": "backend/routes/v1/v1.js", "max_issues_repo_name": "bcgov/metadata-curator", "max_issues_repo_issues_event_min_datetime": "2020-05-28T21:26:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T15:13:01.000Z", "max_forks_repo_path": "backend/routes/v1/v1.js", "max_forks_repo_name": "bcgov/metadata-curator", "max_forks_repo_forks_event_min_datetime": "2021-06-17T17:14:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T19:40:17.000Z"}
{"max_stars_count": 1, "max_issues_count": 21, "max_forks_count": 2, "avg_line_length": 37.5543478261, "max_line_length": 112, "alphanum_fraction": 0.687698987}
var express = require('express');
var path = require('path');


let forumRouter = express.Router();
let forumBridge = require('./forumApi/bridge');
forumRouter = forumBridge(forumRouter);

let formioRouter = express.Router();
let formioBridge = require('./formio/bridge');
formioRouter = formioBridge(formioRouter);

let db = require('../../db/db');

let auth = require('../../modules/auth');

const { Router } = require('express');

module.exports = (router, cache) => {

    //api spec
    router.use('/spec', express.static(path.join(__dirname, 'spec')));

    //api docs
    router.use('/api-docs', function(req, res){
        var docs = require('./docs/docs');
        res.send(docs.getDocHTML("v1"));
    });

    router.use('/forum', auth.requireLoggedIn, forumRouter);
    router.use('/formio', auth.requireLoggedIn, formioRouter);

    router.use('/token', function(req, res){
        if (req.user && req.user.jwt && req.user.refreshToken) {
            res.json(req.user);
        }else{
            res.json({error: "Not logged in"});
        }
    });

    var forumClient = require('./clients/forum_client');
    var formioClient = require('./clients/formio_client');
    var revisionService = require('./services/revisionService');
    var notify = require('./notify/notify')(db);

    var configRoutes = require('../base/config');
    var cfRouter = new Router();
    cfRouter = configRoutes.buildStatic(db, cfRouter);
    cfRouter = configRoutes.buildDynamic(db, cfRouter, auth, cache);
    router.use('/config', cfRouter);

    var packageRoutes = require('../base/packages');
    var pRouter = new Router();

    let ValidationError = require('../../modules/validationError');
    pRouter = packageRoutes.buildStatic(db, pRouter);
    pRouter = packageRoutes.buildDynamic(db, pRouter, auth, ValidationError, cache);
    router.use('/datapackages', pRouter);

    var dataUploadRoutes = require('../base/uploads');
    var uRouter = new Router();
    uRouter = dataUploadRoutes.buildStatic(db, uRouter);
    uRouter = dataUploadRoutes.buildDynamic(db, uRouter, auth, forumClient, notify, revisionService);
    router.use('/datauploads', auth.requireLoggedIn, uRouter);

    var dataProviderRoutes = require('../base/providers');
    var dpRouter = new Router();
    dpRouter = dataProviderRoutes.buildStatic(db, dpRouter);
    dpRouter = dataProviderRoutes.buildDynamic(db, dpRouter, auth, forumClient);
    router.use('/dataproviders', auth.requireLoggedIn, dpRouter);

    var repositoriesRoutes = require('../base/repo');
    var repoRouter = new Router();
    repoRouter = repositoriesRoutes.buildStatic(db, repoRouter);
    repoRouter = repositoriesRoutes.buildDynamic(db, repoRouter, auth, forumClient, cache);
    router.use('/repos', auth.requireLoggedIn, repoRouter);

    var repoBranchesRoutes = require('../base/branches');
    var branchRouter = new Router();
    branchRouter = repoBranchesRoutes.buildStatic(db, branchRouter);
    branchRouter = repoBranchesRoutes.buildDynamic(db, branchRouter, auth, forumClient, revisionService, cache);
    router.use('/repobranches', branchRouter);

    var tableSchemasRoutes = require('../base/tableSchema');
    var tableRouter = new Router();
    tableRouter = tableSchemasRoutes.buildStatic(db, tableRouter);
    tableRouter = tableSchemasRoutes.buildDynamic(db, tableRouter, auth, cache);
    router.use('/tableschemas', auth.requireLoggedIn, tableRouter);

    return router;
}
