{"size": 1330, "ext": "js", "max_stars_repo_path": "src/web/bots/BotsApiServer.js", "max_stars_repo_name": "ben-kaufman/dx-services", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/web/bots/BotsApiServer.js", "max_issues_repo_name": "ben-kaufman/dx-services", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/web/bots/BotsApiServer.js", "max_forks_repo_name": "ben-kaufman/dx-services", "max_forks_repo_forks_event_min_datetime": "2021-07-01T07:05:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-01T07:05:16.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 29.5555555556, "max_line_length": 99, "alphanum_fraction": 0.6947368421}
// const info = require('debug')('INFO-dx-service:BotsApiServer')
const Server = require('../helpers/Server')
const createRouter = require('../helpers/createRouter')

const express = require('express')
const path = require('path')

class BotsApiServer extends Server {
  constructor ({ port = 8081, host, botsService, reportService, ethereumClient, config }) {
    super({ port, host })
    this._botsService = botsService
    this._reportService = reportService
    this._ethereumClient = ethereumClient
    this._config = config
  }

  async _registerRoutes ({ app, contextPath }) {
    const services = {
      botsService: this._botsService,
      reportService: this._reportService
    }

    // Static content
    const mainPages = express.Router()
    mainPages.use(contextPath, express.static(path.join(__dirname, './static')))
    app.use('', mainPages)

    // Get routes
    const mainRoutes = require('./main-routes')(services)
    const reportsRoutes = require('./reports-routes')(services, this._ethereumClient, this._config)

    // Main routes
    app.use('/api', createRouter(mainRoutes))

    app.use('/api/v1/reports', createRouter(reportsRoutes))
  }

  async _getServiceName () {
    const version = await this._botsService.getVersion()
    return 'Bots-API-v' + version
  }
}

module.exports = BotsApiServer
