{"size": 774, "ext": "js", "max_stars_repo_path": "backend/router.js", "max_stars_repo_name": "guitarpawat/blockchain-lotto", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "backend/router.js", "max_issues_repo_name": "guitarpawat/blockchain-lotto", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backend/router.js", "max_forks_repo_name": "guitarpawat/blockchain-lotto", "max_forks_repo_forks_event_min_datetime": "2021-04-27T09:08:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-27T09:08:34.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 21.5, "max_line_length": 86, "alphanum_fraction": 0.6744186047}
const bodyParser = require('body-parser');
const errorHandler = require('./errors/error_handler');
const cors = require('cors')

const controller = require('./controller/controller');

const logger = require('./logger').api;

const express = require('express');
const app = express();
const DefaultPort = 3001;

function initMiddleware() {
    app.use(cors())
    app.use(bodyParser.json());
}

function initErrorHandler() {
    app.use(errorHandler.middleware);
}

function listen(port) {
    app.listen(port, () => logger.info(`Blockchain Lotto listening on port ${port}!`))
}

function start(port) {
    if(!port) {
        port = DefaultPort;
    }
    initMiddleware();
    controller.init(app);
    initErrorHandler();
    listen(port)
}

module.exports.start = start;