diff --git a/src/server.ts b/src/server.ts index d5fc9ec..09dda3c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -147,6 +147,11 @@ const profileRequest = async (request: Request) => { } }; +const genericTwitterRedirect = async (request: Request) => { + const url = new URL(request.url); + return Response.redirect(`${Constants.TWITTER_ROOT}${url.pathname}`, 302); +} + const versionRequest = async (request: Request) => { return new Response( Strings.VERSION_HTML.format({ @@ -237,6 +242,7 @@ router.get('/owoembed', async (request: Request) => { but it's something we might do. Maybe. */ router.get('/:handle', profileRequest); router.get('/:handle/', profileRequest); +router.get('/i/events/:id', genericTwitterRedirect); /* If we don't understand the route structure at all, we'll redirect to GitHub (normal domains) or API docs (api.fxtwitter.com) */ diff --git a/test/index.test.ts b/test/index.test.ts index d6745dc..f8f3b64 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -37,6 +37,17 @@ test('Tweet redirect human', async () => { expect(result.headers.get('location')).toEqual('https://twitter.com/jack/status/20'); }); +test('Twitter moment redirect', async () => { + const result = await cacheWrapper( + new Request('https://fxtwitter.com/i/events/1572638642127966214?t=0UK7Ny-Jnsp-dUGzlb-M8w&s=35', { + method: 'GET', + headers: botHeaders + }) + ); + expect(result.status).toEqual(302); + expect(result.headers.get('location')).toEqual('https://twitter.com/i/events/1572638642127966214'); +}); + test('Tweet response robot', async () => { const result = await cacheWrapper( new Request('https://fxtwitter.com/jack/status/20', {