From 81dbf64eb762c8b4bb0134ecd921e32ae9ddf2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sun, 20 Jan 2019 19:10:19 +0900 Subject: [PATCH] Update reversi routing (#3937) --- src/client/app/desktop/script.ts | 2 +- src/client/app/mobile/script.ts | 2 +- src/server/web/index.ts | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/app/desktop/script.ts b/src/client/app/desktop/script.ts index 95bfe6ec1..05cd79f70 100644 --- a/src/client/app/desktop/script.ts +++ b/src/client/app/desktop/script.ts @@ -147,7 +147,7 @@ init(async (launch) => { { path: '/search', component: MkSearch }, { path: '/tags/:tag', name: 'tag', component: MkTag }, { path: '/share', component: MkShare }, - { path: '/reversi/:game?', component: MkReversi }, + { path: '/games/reversi/:game?', component: MkReversi }, { path: '/@:user', name: 'user', component: MkUser }, { path: '/@:user/following', name: 'userFollowing', component: MkUserFollowingOrFollowers }, { path: '/@:user/followers', name: 'userFollowers', component: MkUserFollowingOrFollowers }, diff --git a/src/client/app/mobile/script.ts b/src/client/app/mobile/script.ts index 52b0d9bbb..bbbdc0ebb 100644 --- a/src/client/app/mobile/script.ts +++ b/src/client/app/mobile/script.ts @@ -135,7 +135,7 @@ init((launch) => { { path: '/search', component: MkSearch }, { path: '/tags/:tag', component: MkTag }, { path: '/share', component: MkShare }, - { path: '/reversi/:game?', name: 'reversi', component: MkReversi }, + { path: '/games/reversi/:game?', name: 'reversi', component: MkReversi }, { path: '/@:user', component: () => import('./views/pages/user.vue').then(m => m.default) }, { path: '/@:user/followers', component: MkFollowers }, { path: '/@:user/following', component: MkFollowing }, diff --git a/src/server/web/index.ts b/src/server/web/index.ts index 7fd9e76cf..945176afd 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -219,6 +219,12 @@ router.get('/info', async ctx => { }); }); +const override = (source: string, target: string, depth: number = 0) => + [, ...target.split('/').filter(x => x), ...source.split('/').filter(x => x).splice(depth)].join('/'); + +router.get('/othello', async ctx => ctx.redirect(override(ctx.URL.pathname, 'games/reversi', 1))); +router.get('/reversi', async ctx => ctx.redirect(override(ctx.URL.pathname, 'games'))); + // Render base html for all requests router.get('*', async ctx => { const meta = await fetchMeta();