mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-03 15:36:39 -04:00
react-twitter-embed
➡️ react-tweet
This commit is contained in:
36
pages/api/tweet.ts
Normal file
36
pages/api/tweet.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getTweet } from "react-tweet/api";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export const config = {
|
||||
runtime: "edge",
|
||||
};
|
||||
|
||||
// eslint-disable-next-line import/no-anonymous-default-export
|
||||
export default async (req: NextRequest) => {
|
||||
const tweetId = req.nextUrl.searchParams.get("id");
|
||||
|
||||
if (typeof tweetId !== "string") {
|
||||
return NextResponse.json({ error: "Bad request." }, { status: 400 });
|
||||
}
|
||||
|
||||
// https://react-tweet.vercel.app/twitter-theme/api-reference
|
||||
try {
|
||||
const tweet = await getTweet(tweetId);
|
||||
return NextResponse.json(
|
||||
{ data: tweet ?? null },
|
||||
{
|
||||
status: tweet ? 200 : 404,
|
||||
headers: {
|
||||
// cache on edge for 12 hours
|
||||
"Cache-Control": "public, max-age=0, s-maxage=43200, stale-while-revalidate",
|
||||
},
|
||||
}
|
||||
);
|
||||
} catch (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
error: any
|
||||
) {
|
||||
return NextResponse.json({ error: error.message ?? "Bad request." }, { status: 400 });
|
||||
}
|
||||
};
|
@ -6,7 +6,7 @@ import { NextSeo } from "next-seo";
|
||||
import Layout from "../components/Layout";
|
||||
import Terminal from "../components/Terminal";
|
||||
import { styled } from "../lib/styles/stitches.config";
|
||||
import type { ReactElement, ComponentProps } from "react";
|
||||
import type { ReactElement, ComponentPropsWithoutRef, ElementRef } from "react";
|
||||
|
||||
// obviously, an interactive VNC display will not work even a little bit server-side
|
||||
const VNC = dynamic(() => import("../components/VNC"), { ssr: false });
|
||||
@ -25,8 +25,8 @@ const Wallpaper = styled("main", {
|
||||
backgroundPosition: "center",
|
||||
});
|
||||
|
||||
const RandomWallpaper = ({ ...rest }: ComponentProps<typeof Wallpaper>) => {
|
||||
const wallpaperRef = useRef<HTMLDivElement>(null);
|
||||
const RandomWallpaper = ({ ...rest }: ComponentPropsWithoutRef<typeof Wallpaper>) => {
|
||||
const wallpaperRef = useRef<ElementRef<typeof Wallpaper>>(null);
|
||||
|
||||
// set a random retro Windows ME desktop tile for the entire content area
|
||||
useEffect(() => {
|
||||
|
Reference in New Issue
Block a user