{"size": 1193, "ext": "js", "max_stars_repo_path": "backend/index.js", "max_stars_repo_name": "magnonellie/twitter-clone", "max_stars_repo_stars_event_min_datetime": "2019-10-02T16:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-02T16:07:06.000Z", "max_issues_repo_path": "backend/index.js", "max_issues_repo_name": "magnonellie/twitter-clone", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backend/index.js", "max_forks_repo_name": "magnonellie/twitter-clone", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.3921568627, "max_line_length": 64, "alphanum_fraction": 0.6445934619}
const Koa = require('koa');
const Router = require('koa-router');
const session = require('koa-session');
const cors = require('@koa/cors');
const { db, initDB } = require('./db.js');
const { passport } = require('./auth.js');

const accounts = require('./routes/account.js');
const tweet = require('./routes/tweet.js');
const user = require('./routes/user.js');

const app = new Koa();
app.proxy = true;

app.use(cors());

app.keys = ['aSecretKeyThatShouldBeReplaced'];
app.use(session({}, app));

app.use(passport.initialize());
app.use(passport.session());

const router = new Router({
  prefix: '/api'
});

router.get('/', async ctx => {
  ctx.body = 'Welcome to the Twitter clone API!';
});

router.use('/account', accounts.routes());
router.use('/tweet', tweet.routes());
router.use('/user', user.routes());

app.use(router.routes());
app.use(router.allowedMethods());

(async () => {
  try {
    await initDB();
    console.log('Database initialized');
  } catch (e) {
    console.error('Database initialization failed! Exiting...');
    console.error(e);
    process.exit(1);
  }
  app.context.db = db;
  app.listen(3000);
  console.log('Application listening on port 3000...');
})();
