Specifying no-cache policy on all API endpoints

This commit is contained in:
Imbus 2024-03-22 23:59:07 +01:00
parent 3610a7413a
commit a1e362acee

View file

@ -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",