Skip to content
This repository was archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Work around koa-router bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeddicord committed May 21, 2017
1 parent ac45118 commit 14267c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions web/server/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function tryAuth(ctx: Context, userId: string, pass: string): Promi
id: -1,
admin: true,
}), {
maxAge: 1000 * 60 * 60 * 2, // 2 days
maxAge: 1000 * 60 * 60 * 24 * 2, // 2 days
domain: ctx.request.hostname,
httpOnly: true,
signed: true,
Expand Down Expand Up @@ -58,7 +58,7 @@ export function setSignedCookie(ctx: Context, id: number, contest: number): void
id,
contest,
}), {
maxAge: 1000 * 60 * 60 * 5, // 5 days
maxAge: 1000 * 60 * 60 * 24 * 5, // 5 days
domain: ctx.request.hostname,
httpOnly: true,
signed: true,
Expand Down
13 changes: 7 additions & 6 deletions web/server/api/contest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ import { getProblem } from '../problems';
import { RequestError, NotFoundError } from '../util/errors';

const routes = new Router({prefix: '/contests/:contest_id'});
routes.use(contestAccess);
// BROKEN: https://github.com/alexmingoia/koa-router/issues/347
// routes.use(contestAccess);

// get a single contest's details
routes.get('/', contestIsActive, async (ctx, next) => {
routes.get('/', contestAccess, contestIsActive, async (ctx, next) => {
const id = ctx.params.contest_id;
const contest = await getContestCached(id, ctx);
ctx.body = contest;
});

routes.get('/problems/:problem', contestIsActive, contestHasProblem, async (ctx, next) => {
routes.get('/problems/:problem', contestAccess, contestIsActive, contestHasProblem, async (ctx, next) => {
// sanity check
const problemName = ctx.params.problem;
const problem = getProblem(problemName);
Expand Down Expand Up @@ -64,7 +65,7 @@ routes.get('/problems/:problem', contestIsActive, contestHasProblem, async (ctx,
}
});

routes.post('/problems/:problem', contestIsActive, contestHasProblem, async (ctx, next) => {
routes.post('/problems/:problem', contestAccess, contestIsActive, contestHasProblem, async (ctx, next) => {
const userId = ctx.state.user.id;
const contestId = ctx.params.contest_id;
const problem = ctx.params.problem;
Expand All @@ -90,7 +91,7 @@ routes.post('/problems/:problem', contestIsActive, contestHasProblem, async (ctx
ctx.body = {id: sub.id};
});

routes.get('/score', async (ctx, next) => {
routes.get('/score', contestAccess, async (ctx, next) => {
const userId = ctx.state.user.id;
const user = await dbUsers.getUser(userId);

Expand All @@ -106,7 +107,7 @@ routes.get('/score', async (ctx, next) => {
};
});

routes.get('/leaderboard', async (ctx, next) => {
routes.get('/leaderboard', contestAccess, async (ctx, next) => {
// check cache for leaderboard
const id = ctx.params.contest_id;
const cacheKey = `contest/${id}/leaderboard`;
Expand Down

0 comments on commit 14267c6

Please sign in to comment.