Changes related to api in both client and server

This commit is contained in:
Imbus 2023-10-20 22:49:09 +02:00
parent 8cfbfd17b6
commit 0ea21cfaf3
4 changed files with 51 additions and 11 deletions

View file

@ -20,20 +20,20 @@ export interface Post extends NewPost {
export async function getPosts(): Promise<Post[]> {
// const res = await fetch(`${API_URL}/posts`);
const res = await fetch("/api/");
const res = await fetch("/api/posts");
const data = await res.json();
return data;
}
export async function getPost(id: string): Promise<Post> {
const res = await fetch(`/api/${id}`);
const res = await fetch(`/api/posts/${id}`);
const data = await res.json();
return data;
}
export async function createPost(post: NewPost): Promise<void> {
// await fetch(`${API_URL}`, {
await fetch("/api/", {
await fetch("/api/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",