Skip to content

Commit

Permalink
added api prefix and axios error 4
Browse files Browse the repository at this point in the history
  • Loading branch information
parkersarahl committed Jul 10, 2024
1 parent acce2cd commit fbaba12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import "./App.css";
import Todo from "./Todo";
import axios from "axios";
import { host } from "./constants";

export type TodoDTO = {
id: number;
Expand All @@ -10,6 +11,8 @@ export type TodoDTO = {
done: boolean;
};



function App() {
const [todos, setTodos] = useState<TodoDTO[]>([]);
const [newTodo, setNewTodo] = useState<TodoDTO>({
Expand All @@ -20,7 +23,8 @@ function App() {
});

useEffect(() => {
axios.get("http://localhost:3000/todos").then((response) => {
console.log("HOST", host);
axios.get(`http://${host}:3000/api/todos`).then((response) => {
setTodos(response.data);
});
}, []);
Expand All @@ -39,7 +43,7 @@ function App() {
};

const addTodo = () => {
axios.post("http://localhost:3000/todos", newTodo).then((response) => {
axios.post("http://localhost:3000/api/todos", newTodo).then((response) => {
setTodos(response.data);
});
};
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Todo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react";
import { TodoDTO } from "./App";
import axios from "axios";
import { FaEdit, FaCheck } from "react-icons/fa";
import { host } from "./constants";

type Props = {
todo: TodoDTO;
Expand All @@ -28,7 +29,7 @@ const Todo = ({ todo, updateTodos }: Props) => {
const editTodo = (key: string, value: string | boolean) => {
const updatedTodo = { ...todo, [key]: value };
axios
.put(`http://localhost:3000/todos/${todo.id}`, {
.put(`http://${host}:3000/api/todos/${todo.id}`, {
todo: updatedTodo,
})
.then((response) => {
Expand Down
Empty file added frontend/src/constants.ts
Empty file.

0 comments on commit fbaba12

Please sign in to comment.