Open History to see the last commit
1import axios from 'redaxios'
2β
3export class NotFoundError extends Error {}
4β
5let queryURL = 'https://jsonplaceholder.typicode.com'
6β
7if (import.meta.env.VITE_NODE_ENV === 'test') {
8 queryURL = `http://localhost:${import.meta.env.VITE_EXTERNAL_PORT}`
9}
10β
11export const fetchPosts = async () => {
12 console.info('Fetching posts...')
13 return axios.get(`${queryURL}/posts`).then((r) => r.data.slice(0, 10))
14}
15β
16export const fetchPost = async (postId) => {
17 console.info(`Fetching post with id ${postId}...`)
18 const post = await axios
19 .get(`${queryURL}/posts/${postId}`)
20 .then((r) => r.data)
21β
22 if (!post) {
23 throw new NotFoundError(`Post with id "${postId}" not found!`)
24 }
25β
26 return post
27}