Changes related to api in both client and server
This commit is contained in:
parent
8cfbfd17b6
commit
0ea21cfaf3
4 changed files with 51 additions and 11 deletions
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue