Upgrade itty-router to v3

This commit is contained in:
dangered wolf 2023-03-20 01:53:46 -04:00
parent 5f20e2c4fe
commit 028245f739
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
3 changed files with 15 additions and 15 deletions

14
package-lock.json generated
View file

@ -9,7 +9,7 @@
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"itty-router": "^2.6.6",
"itty-router": "^3.0.11",
"toucan-js": "^2.7.0"
},
"devDependencies": {
@ -4488,9 +4488,9 @@
}
},
"node_modules/itty-router": {
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/itty-router/-/itty-router-2.6.6.tgz",
"integrity": "sha512-hIPHtXGymCX7Lzb2I4G6JgZFE4QEEQwst9GORK7sMYUpJvLfy4yZJr95r04e8DzoAnj6HcxM2m4TbK+juu+18g=="
"version": "3.0.11",
"resolved": "https://registry.npmjs.org/itty-router/-/itty-router-3.0.11.tgz",
"integrity": "sha512-vWsoHBi2CmU15YzyUeHjRfjdySL2jqZQKA9jP1LXkBcLJAo0KQNVlQMvhtzG0mzABhVYifeBF97UkrrpuTCWYQ=="
},
"node_modules/jest": {
"version": "29.5.0",
@ -10894,9 +10894,9 @@
}
},
"itty-router": {
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/itty-router/-/itty-router-2.6.6.tgz",
"integrity": "sha512-hIPHtXGymCX7Lzb2I4G6JgZFE4QEEQwst9GORK7sMYUpJvLfy4yZJr95r04e8DzoAnj6HcxM2m4TbK+juu+18g=="
"version": "3.0.11",
"resolved": "https://registry.npmjs.org/itty-router/-/itty-router-3.0.11.tgz",
"integrity": "sha512-vWsoHBi2CmU15YzyUeHjRfjdySL2jqZQKA9jP1LXkBcLJAo0KQNVlQMvhtzG0mzABhVYifeBF97UkrrpuTCWYQ=="
},
"jest": {
"version": "29.5.0",

View file

@ -38,7 +38,7 @@
"wrangler": "^2.12.3"
},
"dependencies": {
"itty-router": "^2.6.6",
"itty-router": "^3.0.11",
"toucan-js": "^2.7.0"
}
}

View file

@ -1,6 +1,6 @@
import Toucan from 'toucan-js';
import { Router } from 'itty-router';
import { IRequest, Router } from 'itty-router';
import { Constants } from './constants';
import { handleStatus } from './status';
import { Strings } from './strings';
@ -12,7 +12,7 @@ const router = Router();
/* Handler for status (Tweet) request */
const statusRequest = async (
request: Request,
request: IRequest,
event: FetchEvent,
flags: InputFlags = {}
) => {
@ -142,7 +142,7 @@ const statusRequest = async (
/* Redirects to user profile when linked.
We don't do any fancy special embeds yet, just Twitter default embeds. */
const profileRequest = async (request: Request) => {
const profileRequest = async (request: IRequest) => {
const { handle } = request.params;
const url = new URL(request.url);
@ -154,12 +154,12 @@ const profileRequest = async (request: Request) => {
}
};
const genericTwitterRedirect = async (request: Request) => {
const genericTwitterRedirect = async (request: IRequest) => {
const url = new URL(request.url);
return Response.redirect(`${Constants.TWITTER_ROOT}${url.pathname}`, 302);
};
const versionRequest = async (request: Request) => {
const versionRequest = async (request: IRequest) => {
return new Response(
Strings.VERSION_HTML.format({
rtt: request.cf?.clientTcpRtt ? `🏓 ${request.cf.clientTcpRtt} ms RTT` : '',
@ -213,7 +213,7 @@ router.get('/version', versionRequest);
/* Oembeds (used by Discord to enhance responses)
Yes, I actually made the endpoint /owoembed. Deal with it. */
router.get('/owoembed', async (request: Request) => {
router.get('/owoembed', async (request: IRequest) => {
console.log('oembed hit!');
const { searchParams } = new URL(request.url);
@ -260,7 +260,7 @@ router.get('/hashtag/:hashtag', genericTwitterRedirect);
/* If we don't understand the route structure at all, we'll
redirect to GitHub (normal domains) or API docs (api.fxtwitter.com) */
router.get('*', async (request: Request) => {
router.get('*', async (request: IRequest) => {
const url = new URL(request.url);
if (Constants.API_HOST_LIST.includes(url.hostname)) {