{"size": 850, "ext": "js", "max_stars_repo_path": "src/index.js", "max_stars_repo_name": "bloqpriv/ethereum-transaction-tracer", "max_stars_repo_stars_event_min_datetime": "2021-06-11T06:41:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-11T06:41:44.000Z", "max_issues_repo_path": "src/index.js", "max_issues_repo_name": "bloqpriv/ethereum-transaction-tracer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/index.js", "max_forks_repo_name": "bloqpriv/ethereum-transaction-tracer", "max_forks_repo_forks_event_min_datetime": "2018-05-28T01:34:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T08:58:31.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 5, "avg_line_length": 21.7948717949, "max_line_length": 60, "alphanum_fraction": 0.7164705882}
'use strict'

const { corsOrigins } = require('config')
const beforeExit = require('before-exit')
const corsMiddleware = require('restify-cors-middleware')
const restify = require('restify')

const logger = require('./logger')
const routes = require('./routes')

const server = restify.createServer()

const cors = corsMiddleware({ origins: corsOrigins })
server.pre(cors.preflight)
server.use(cors.actual)

server.use(restify.plugins.queryParser())

function logRequest (req, res, next) {
  logger.verbose('-->', req.method, req.url)
  return next()
}

server.use(logRequest)

routes.applyRoutes(server)

beforeExit.do(function (signal) {
  logger.error('Tracer shutting down API on signal', signal)
})

function start (port) {
  server.listen(port, function () {
    logger.info(`Tracer started on port ${port}`)
  })
}

module.exports = { start }
