{"size": 1164, "ext": "js", "max_stars_repo_path": "admin-system/backend/app/router.js", "max_stars_repo_name": "yugasun/serverless-practice", "max_stars_repo_stars_event_min_datetime": "2019-11-22T11:36:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-02T15:13:15.000Z", "max_issues_repo_path": "backend/app/router.js", "max_issues_repo_name": "serverless-plus/serverless-admin-system", "max_issues_repo_issues_event_min_datetime": "2020-11-02T11:21:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-25T10:48:02.000Z", "max_forks_repo_path": "backend/app/router.js", "max_forks_repo_name": "serverless-plus/serverless-admin-system", "max_forks_repo_forks_event_min_datetime": "2019-12-08T00:44:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-16T09:56:27.000Z"}
{"max_stars_count": 58, "max_issues_count": 2, "max_forks_count": 18, "avg_line_length": 26.4545454545, "max_line_length": 59, "alphanum_fraction": 0.6254295533}
'use strict';

const koajwt = require('koa-jwt2');

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, jwt } = app;
  router.get('/', controller.home.index);

  router.get('/get-config', controller.home.getAppConfig);
  router.post('/login', controller.home.login);
  router.get('/user-info', jwt, controller.home.userInfo);
  const isRevokedAsync = function(req, payload) {
    return new Promise(resolve => {
      try {
        const userId = payload.id;
        const tokenKey = `token_${userId}`;
        const token = app.redis.get(tokenKey);
        if (token) {
          app.redis.del(tokenKey);
        }
        resolve(false);
      } catch (e) {
        resolve(true);
      }

    });
  };
  router.post('/logout', koajwt({
    secret: app.config.jwt.secret,
    credentialsRequired: false,
    isRevoked: isRevokedAsync,
  }), controller.home.logout);

  router.get('/authing/auth', controller.home.authingAuth);


  router.resources('roles', '/roles', controller.role);
  router.resources('users', '/users', controller.user);
  router.resources('posts', '/posts', controller.post);
};
