@@ -18,11 +18,15 @@ type TodoStore = {
1818 deleteTodo : ( id : number ) => void ;
1919} ;
2020
21+ const URL = process . env . NEXT_PUBLIC_VERCEL_URL
22+ ? `https://${ process . env . NEXT_PUBLIC_VERCEL_URL } /api`
23+ : "http://localhost:3000/api" ;
24+
2125export const useStore = create < TodoStore > ( ( set ) => ( {
2226 todos : [ ] ,
2327 fetchTodos : async ( ) => {
2428 try {
25- const response = await fetch ( "/api/ todos" ) ;
29+ const response = await fetch ( ` ${ URL } / todos` ) ;
2630 const todos = await response . json ( ) ;
2731 set ( { todos } ) ;
2832 } catch ( error ) {
@@ -31,7 +35,7 @@ export const useStore = create<TodoStore>((set) => ({
3135 } ,
3236 addTodo : async ( todo ) => {
3337 try {
34- const response = await fetch ( "/api/ todos" , {
38+ const response = await fetch ( ` ${ URL } / todos` , {
3539 method : "POST" ,
3640 headers : {
3741 "Content-Type" : "application/json" ,
@@ -46,7 +50,7 @@ export const useStore = create<TodoStore>((set) => ({
4650 } ,
4751 updateTodo : async ( updatedTodo ) => {
4852 try {
49- const response = await fetch ( `/api /todos/${ updatedTodo . id } ` , {
53+ const response = await fetch ( `${ URL } /todos/${ updatedTodo . id } ` , {
5054 method : "PATCH" ,
5155 headers : {
5256 "Content-Type" : "application/json" ,
@@ -65,7 +69,7 @@ export const useStore = create<TodoStore>((set) => ({
6569 } ,
6670 deleteTodo : async ( id ) => {
6771 try {
68- await fetch ( `/api /todos/${ id } ` , {
72+ await fetch ( `${ URL } /todos/${ id } ` , {
6973 method : "DELETE" ,
7074 } ) ;
7175 set ( ( state ) => ( {
0 commit comments