"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _koa = _interopRequireDefault(require("koa"));

var _koaLogger = _interopRequireDefault(require("koa-logger"));

var _koaHelmet = _interopRequireDefault(require("koa-helmet"));

var _koaStatic = _interopRequireDefault(require("koa-static"));

var _koaCompress = _interopRequireDefault(require("koa-compress"));

var _koaSslify = _interopRequireWildcard(require("koa-sslify"));

var Sentry = _interopRequireWildcard(require("@sentry/node"));

var _path = _interopRequireDefault(require("path"));

var _config = require("./config");

var _ = _interopRequireDefault(require("./404"));

var _app = _interopRequireDefault(require("./app"));

/* eslint-disable no-console */
const koa = new _koa.default();
Sentry.init({
  dsn: process.env.SENTRY_DSN,
  debug: _config.PRODUCTION,
  release: process.env.SENTRY_RELEASE,
  environment: process.env.SENTRY_ENVIRONMENT
});

if (_config.PRODUCTION) {
  koa.on("error", err => {
    Sentry.captureException(err);
  });
  koa.use((0, _koaCompress.default)());
  koa.use((0, _koaSslify.default)({
    resolver: _koaSslify.xForwardedProtoResolver
  }));
}

koa.use((0, _koaHelmet.default)());
koa.use((0, _koaLogger.default)());
const YEAR = 1000 * 60 * 60 * 24 * 365;
const opts = {
  maxage: _config.PRODUCTION ? YEAR : 0
};
koa.use((0, _koaStatic.default)(_path.default.join(__dirname, "../static/"), opts));
koa.use((0, _koaStatic.default)(_path.default.join(__dirname, "../../public/"), opts));
koa.use(_.default);
koa.use(_app.default);
koa.listen(_config.PORT);