21 // Buscar projetos ao carregar o dashboard
22 useEffect(() => {
23 const fetchProjects = async () => {
24 try {
25 const response = await fetch("/api/projects", {
26 method: "GET",
27 credentials: "include",
52 };
53
54 fetchProjects();
55 }, []);
56
2import app from "./backend/index.ts";
3
4// Exportar a função fetch para o Val Town
5export default app;
19 return c.json(response);
20 } catch (error) {
21 console.error("Error fetching pests/diseases:", error);
22 const response: ApiResponse<null> = {
23 success: false,
55 return c.json(response);
56 } catch (error) {
57 console.error(`Error fetching pest/disease with ID ${c.req.param("id")}:`, error);
58 const response: ApiResponse<null> = {
59 success: false,
44
45 // Make the API request to OpenRouter
46 const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
47 method: "POST",
48 headers: {
46
47 try {
48 const response = await fetch("/api/auth/register", {
49 method: "POST",
50 headers: {
26
27 try {
28 const response = await fetch("/api/auth/login", {
29 method: "POST",
30 headers: {
14 const checkAuth = async () => {
15 try {
16 const response = await fetch("/api/auth/me", {
17 method: "GET",
18 credentials: "include",
50 const handleLogout = async () => {
51 try {
52 await fetch("/api/auth/logout", {
53 method: "POST",
54 credentials: "include",
8 const [error, setError] = useState(null);
9
10 const fetchData = async () => {
11 try {
12 const userEndpoint = new URL(USER_ENDPOINT, window.location.origin);
13
14 const res = await fetch(userEndpoint);
15 const data = await res.json();
16 if (!res.ok) {
33
34 useEffect(() => {
35 fetchData();
36 }, []);
37
38 return { data, loading, error, refetch: fetchData };
39}
40
9 const [error, setError] = useState(null);
10
11 const fetchData = async () => {
12 try {
13 const projectEndpoint = new URL(PROJECT_ENDPOINT, window.location.origin);
17 if (branchId) filesEndpoint.searchParams.append("branchId", branchId);
18
19 const { project } = await fetch(projectEndpoint).then((res) =>
20 res.json()
21 );
22 const { files } = await fetch(filesEndpoint).then((res) => res.json());
23
24 setData({ project, files });
34 useEffect(() => {
35 if (!projectId) return;
36 fetchData();
37 }, [projectId, branchId]);
38
39 return { data, loading, error, refetch: fetchData };
40}
41
8 const [error, setError] = useState(null);
9
10 const fetchData = async () => {
11 try {
12 const res = await fetch(ENDPOINT);
13 const data = await res.json();
14 if (!res.ok) {
32
33 useEffect(() => {
34 fetchData();
35 }, []);
36
37 return { data, loading, error, refetch: fetchData };
38}
39