{"size": 1122, "ext": "js", "max_stars_repo_path": "app/controllers/api/controller_api.js", "max_stars_repo_name": "mirandachristanto/my-service", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/controllers/api/controller_api.js", "max_issues_repo_name": "mirandachristanto/my-service", "max_issues_repo_issues_event_min_datetime": "2021-09-02T22:08:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T22:08:50.000Z", "max_forks_repo_path": "app/controllers/api/controller_api.js", "max_forks_repo_name": "mirandachristanto/my-service", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 33.0, "max_line_length": 109, "alphanum_fraction": 0.6541889483}
const basicAuth = require('basic-auth')
const express = require('express')
const router = express.Router()
const api_log = require('../../module/log')
const api_response = require('../../module/api_response')
const api_config = require('../../config/config_api')
const c_v1 = require('./v1/request')

router.use(async function(req, res){
    api_log.log_request(req);
    req.next();
})

router.use(async function(req, res, next){
    try{
        var user = basicAuth(req)
        if(user.name == api_config.username_basic && user.pass == api_config.password_basic){
            next()
        }else{
            response = await api_response.create_response(1002,"Error : Wrong Header Data",null);
            res.setHeader('Content-Type', 'application/json');res.status(200).send(JSON.stringify(response));
        }
    }
    catch(e){
        console.log(e)
        response = await api_response.create_response(1002,"Error : Wrong Header Data",null);
        res.setHeader('Content-Type', 'application/json');res.status(200).send(JSON.stringify(response));
    }
})

router.use("/v1", c_v1)


module.exports = router