Skip to content

Commit

Permalink
reintroducing .env for local run
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelebarre committed Oct 30, 2024
1 parent c09ee3c commit 04cd19c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.guitar</groupId>
Expand Down
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_URL=http://localhost:8080
12 changes: 6 additions & 6 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mui/icons-material": "^6.1.4",
"@mui/material": "^6.1.4",
"@mui/icons-material": "^6.1.5",
"@mui/material": "^6.1.5",
"@react-pdf/renderer": "^4.0.0",
"axios": "^1.7.7",
"file-saver": "^2.0.5",
Expand All @@ -31,17 +31,17 @@
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/file-saver": "^2.0.7",
"@types/react": "^18.3.11",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react-resizable": "^3.0.8",
"@vitejs/plugin-react": "^4.3.3",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.13",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.10.0",
"vite": "^5.4.9"
"typescript-eslint": "^8.12.2",
"vite": "^5.4.10"
}


Expand Down
32 changes: 20 additions & 12 deletions frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ import { Comment, Playlist } from "../types/types";
// }

// Create axios instance with simplified baseURL
// const api = axios.create({
// baseURL: import.meta.env.VITE_API_BASE_URL || "/api" // Proxy will route to backend on port 80
// });
const api = axios.create({
baseURL: import.meta.env.VITE_API_URL || "/api" // Proxy will route to backend on port 80
});


// Debugging the axios instance baseURL
// console.log("Axios baseURL:", api.defaults.baseURL);
console.log("Axios baseURL:", api.defaults.baseURL);

// Fetch list of file names (tutorials) from the backend
export const getTutorials = async (): Promise<string[]> => {
const response = await axios.get("/api/tutorials/");
return response.data;
try {
const response = await api.get("/api/tutorials/");
return response.data;

}
catch (error) {
console.error("Error retrieving Tutorials ToC:", error);
return [];
}
};

// Utility function to URL-encode the file name
Expand Down Expand Up @@ -62,7 +70,7 @@ export const getTablatureUrl = async (

// Fetch comments for a specific tutorial
export const getComments = async (tutorialId: number): Promise<Comment[]> => {
const response = await axios.get(`/api/comments/tutorial/${tutorialId}`);
const response = await api.get(`/api/comments/tutorial/${tutorialId}`);
return response.data;
};

Expand All @@ -71,18 +79,18 @@ export const postComment = async (
tutorialId: number,
text: string
): Promise<void> => {
await axios.post("/api/comments", { tutorialId, text });
await api.post("/api/comments", { tutorialId, text });
};

// Fetch all playlists
export const getPlaylists = async (): Promise<Playlist[]> => {
const response = await axios.get("/api/playlists");
const response = await api.get("/api/playlists");
return response.data;
};

// Create a new playlist
export const createPlaylist = async (name: string): Promise<void> => {
await axios.post("/api/playlists", { name });
await api.post("/api/playlists", { name });
};

// Post a new annotation (highlight)
Expand All @@ -92,7 +100,7 @@ export const postAnnotation = async (
position: any,
comment: { text: string; emoji: string }
): Promise<void> => {
await axios.post("/api/annotations/", {
await api.post("/api/annotations/", {
tutorialId,
content,
position,
Expand All @@ -102,5 +110,5 @@ export const postAnnotation = async (

// Delete an annotation by its ID
export const deleteAnnotation = async (annotationId: string): Promise<void> => {
await axios.delete(`/api/annotations/${annotationId}`);
await api.delete(`/api/annotations/${annotationId}`);
};
5 changes: 3 additions & 2 deletions frontend/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import {
Expand All @@ -14,7 +15,8 @@ const HomePage: React.FC = () => {
const [tutorials, setTutorials] = useState<string[]>([]);

useEffect(() => {
getTutorials().then((data) => setTutorials(data));
getTutorials().then((data) =>
setTutorials(data));
}, []);

return (
Expand All @@ -35,7 +37,6 @@ const HomePage: React.FC = () => {
/>
</ListItem>


))}
</List>
</Container>
Expand Down

0 comments on commit 04cd19c

Please sign in to comment.