anum-frontend/app/routes/api.posts.$postId.ts
2026-02-07 16:12:58 +02:00

16 lines
No EOL
480 B
TypeScript

import { type LoaderFunctionArgs } from "react-router";
export async function loader({ params, context }: LoaderFunctionArgs) {
const { postId } = params;
// 'context.cloudflare.env' contains your bindings
const { API } = context.cloudflare.env;
// Use the Service Binding to talk to the backend
// This is much faster than a standard fetch over the internet
const response = await API.fetch(
`http://internal/posts/${postId}/view`
);
return response;
}