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[]> { | 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(); |   const data = await res.json(); | ||||||
|   return data; |   return data; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getPost(id: string): Promise<Post> { | 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(); |   const data = await res.json(); | ||||||
|   return data; |   return data; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function createPost(post: NewPost): Promise<void> { | export async function createPost(post: NewPost): Promise<void> { | ||||||
|   await fetch("/api/posts", { |   await fetch("/api/posts", { | ||||||
|  |     cache: "no-cache", | ||||||
|     method: "POST", |     method: "POST", | ||||||
|     headers: { |     headers: { | ||||||
|       "Content-Type": "application/json", |       "Content-Type": "application/json", | ||||||
|  | @ -69,6 +70,7 @@ export async function createPost(post: NewPost): Promise<void> { | ||||||
| 
 | 
 | ||||||
| export async function createComment(comment: NewComment): Promise<void> { | export async function createComment(comment: NewComment): Promise<void> { | ||||||
|   await fetch("/api/comments", { |   await fetch("/api/comments", { | ||||||
|  |     cache: "no-cache", | ||||||
|     method: "POST", |     method: "POST", | ||||||
|     headers: { |     headers: { | ||||||
|       "Content-Type": "application/json", |       "Content-Type": "application/json", | ||||||
|  | @ -84,7 +86,10 @@ export async function getComments( | ||||||
|   offset: number |   offset: number | ||||||
| ): Promise<PublicComment[]> { | ): Promise<PublicComment[]> { | ||||||
|   const res = await fetch( |   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(); |   const data = await res.json(); | ||||||
|   return data; |   return data; | ||||||
|  | @ -103,6 +108,7 @@ export async function getEngagementCount(postId: string): Promise<number> { | ||||||
| 
 | 
 | ||||||
| export async function deletePost(id: string, token: string): Promise<Response> { | export async function deletePost(id: string, token: string): Promise<Response> { | ||||||
|   return await fetch(`/api/posts/${id}`, { |   return await fetch(`/api/posts/${id}`, { | ||||||
|  |     cache: "no-cache", | ||||||
|     method: "DELETE", |     method: "DELETE", | ||||||
|     headers: { |     headers: { | ||||||
|       "Content-Type": "application/json", |       "Content-Type": "application/json", | ||||||
|  | @ -118,6 +124,7 @@ export async function submitRegistration( | ||||||
|   captcha: string |   captcha: string | ||||||
| ): Promise<AuthResponse | undefined> { | ): Promise<AuthResponse | undefined> { | ||||||
|   const response = await fetch("/api/register", { |   const response = await fetch("/api/register", { | ||||||
|  |     cache: "no-cache", | ||||||
|     method: "POST", |     method: "POST", | ||||||
|     headers: { "Content-Type": "application/json" }, |     headers: { "Content-Type": "application/json" }, | ||||||
|     body: JSON.stringify({ username, password, captcha }), |     body: JSON.stringify({ username, password, captcha }), | ||||||
|  | @ -133,6 +140,7 @@ export async function submitLogin( | ||||||
| ): Promise<AuthResponse | undefined> { | ): Promise<AuthResponse | undefined> { | ||||||
|   if (username == "" || password == "") return; |   if (username == "" || password == "") return; | ||||||
|   const response = await fetch("/api/login", { |   const response = await fetch("/api/login", { | ||||||
|  |     cache: "no-cache", | ||||||
|     method: "POST", |     method: "POST", | ||||||
|     headers: { "Content-Type": "application/json" }, |     headers: { "Content-Type": "application/json" }, | ||||||
|     body: JSON.stringify({ username, password }), |     body: JSON.stringify({ username, password }), | ||||||
|  | @ -148,6 +156,7 @@ export async function submitLogin( | ||||||
|  */ |  */ | ||||||
| export async function engage(postId: string, token: string): Promise<Response> { | export async function engage(postId: string, token: string): Promise<Response> { | ||||||
|   return await fetch(`/api/posts/${postId}/engage`, { |   return await fetch(`/api/posts/${postId}/engage`, { | ||||||
|  |     cache: "no-cache", | ||||||
|     method: "POST", |     method: "POST", | ||||||
|     headers: { |     headers: { | ||||||
|       "Content-Type": "application/json", |       "Content-Type": "application/json", | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Imbus
						Imbus