Specifying no-cache policy on all API endpoints
This commit is contained in:
parent
3610a7413a
commit
a1e362acee
1 changed files with 13 additions and 4 deletions
|
@ -46,19 +46,20 @@ export interface PublicComment {
|
|||
}
|
||||
|
||||
export async function getPosts(): Promise<Post[]> {
|
||||
const res = await fetch("/api/posts");
|
||||
const res = await fetch("/api/posts", { cache: "no-cache" });
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getPost(id: string): Promise<Post> {
|
||||
const res = await fetch(`/api/posts/${id}`);
|
||||
const res = await fetch(`/api/posts/${id}`, { cache: "no-cache" });
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createPost(post: NewPost): Promise<void> {
|
||||
await fetch("/api/posts", {
|
||||
cache: "no-cache",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -69,6 +70,7 @@ export async function createPost(post: NewPost): Promise<void> {
|
|||
|
||||
export async function createComment(comment: NewComment): Promise<void> {
|
||||
await fetch("/api/comments", {
|
||||
cache: "no-cache",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -84,13 +86,16 @@ export async function getComments(
|
|||
offset: number
|
||||
): Promise<PublicComment[]> {
|
||||
const res = await fetch(
|
||||
`/api/comments?post_id=${postId}&limit=${limit}&offset=${offset}`
|
||||
`/api/comments?post_id=${postId}&limit=${limit}&offset=${offset}`,
|
||||
{
|
||||
cache: "no-cache",
|
||||
}
|
||||
);
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets the Engagement counts for a post by postId
|
||||
* @param postId The id of the post
|
||||
* @returns {Promise<number>} A promise that contains number of post engages
|
||||
|
@ -103,6 +108,7 @@ export async function getEngagementCount(postId: string): Promise<number> {
|
|||
|
||||
export async function deletePost(id: string, token: string): Promise<Response> {
|
||||
return await fetch(`/api/posts/${id}`, {
|
||||
cache: "no-cache",
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -118,6 +124,7 @@ export async function submitRegistration(
|
|||
captcha: string
|
||||
): Promise<AuthResponse | undefined> {
|
||||
const response = await fetch("/api/register", {
|
||||
cache: "no-cache",
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password, captcha }),
|
||||
|
@ -133,6 +140,7 @@ export async function submitLogin(
|
|||
): Promise<AuthResponse | undefined> {
|
||||
if (username == "" || password == "") return;
|
||||
const response = await fetch("/api/login", {
|
||||
cache: "no-cache",
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password }),
|
||||
|
@ -148,6 +156,7 @@ export async function submitLogin(
|
|||
*/
|
||||
export async function engage(postId: string, token: string): Promise<Response> {
|
||||
return await fetch(`/api/posts/${postId}/engage`, {
|
||||
cache: "no-cache",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
Loading…
Reference in a new issue