13 lines
388 B
TypeScript
13 lines
388 B
TypeScript
import type { Post } from "../types";
|
|
|
|
const url =
|
|
import.meta.env.NODE_ENV === "development"
|
|
? "http://payload:3001"
|
|
: `https://${import.meta.env.PAYLOAD_URL}`;
|
|
|
|
export const getPosts = async () =>
|
|
(await (await fetch(`${url}/api/posts`)).json()).docs as Post[];
|
|
|
|
export const getPost = async (id: string) =>
|
|
(await (await fetch(`${url}/api/posts/${id}`)).json()) as Post;
|