#57-environmental-variables #59

Merged
juggy1233 merged 6 commits from #57-environmental-variables into master 2023-04-14 14:44:36 -04:00
7 changed files with 31 additions and 11 deletions
Showing only changes of commit c1a8f04dc7 - Show all commits

View File

@@ -4,11 +4,29 @@ services:
image: comp2707-frontend
build: frontend/
container_name: comp2707-frontend
environment:
- BACKEND_URL="http://backend:5000"
ports:
- 8080:8080
backend:
image: comp2707-backend
build: backend/
container_name: comp2707-backend
environment:
- DB_HOST=db
- DB_USER=joe
- DB_PASSWORD=mama
ports:
- 5000:5000
db:
image: mariadb:latest
environment:
- MARIADB_USER=joe
- MARIADB_PASWWORD=mama
- MARIADB_ROOT_PASSWORD=mama
volumes:
- db-volume:/var/lib/mysql
volumes:
db-volume:
driver: local

View File

@@ -12,7 +12,7 @@ const CoursesWidget = ({ className = "" }) => {
if (!currentUser.id) {
return;
}
makeRequest({ url: `http://localhost:5000/user/${currentUser.id}/courses` })
makeRequest({ endpoint: `user/${currentUser.id}/courses` })
.then((resp) => resp.json())
.then((data) => {
setCourseData(data.courses);

View File

@@ -7,7 +7,7 @@ const CoursePage = ({ id }) => {
const [courseData, setCourseData] = useState({});
useEffect(() => {
makeRequest({ url: `http://localhost:5000/course/${id}` })
makeRequest({ endpoint: `course/${id}` })
.then((resp) => resp.json())
.then((data) => {
setCourseData(data);

View File

@@ -11,7 +11,7 @@ const ManagePage = () => {
useEffect(() => {
makeRequest({
url: `http://localhost:5000/user/${currentUser.id}/courses`,
endpoint: `user/${currentUser.id}/courses`,
method: "GET",
})
.then((req) => req.json())

View File

@@ -9,7 +9,7 @@ const ManageStutentsPage = ({ cid }) => {
const submitStudentForm = async (username) => {
await makeRequest({
url: `http://localhost:5000/user/${username}/enroll/${cid}`,
endpoint: `user/${username}/enroll/${cid}`,
method: "POST",
});
window.location.reload();
@@ -48,7 +48,7 @@ const ManageStutentsPage = ({ cid }) => {
};
useEffect(() => {
makeRequest({
url: `http://localhost:5000/course/${cid}/students`,
endpoint: `course/${cid}/students`,
method: "GET",
})
.then((req) => req.json())
@@ -62,7 +62,7 @@ const ManageStutentsPage = ({ cid }) => {
const sendUnenrollRequest = (uid) => {
makeRequest({
url: `http://localhost:5000/user/${uid}/enroll/${cid}`,
endpoint: `user/${uid}/enroll/${cid}`,
method: "DELETE",
}).then((resp) => {
window.location.reload();

View File

@@ -17,7 +17,7 @@ const RegisterPage = () => {
const sendRegisterRequest = (e) => {
e?.preventDefault();
makeRequest({
url: "http://localhost:5000/register",
endpoint: "register",
method: "POST",
body: {
role,

View File

@@ -1,4 +1,6 @@
const makeRequest = ({ url, method, body = null }): Promise<Response> => {
const { REACT_APP_BACKEND_URL } = process.env;
const makeRequest = ({ endpoint, method, body = null }): Promise<Response> => {
const req: RequestInit = {
method: method,
credentials: "include",
@@ -8,7 +10,7 @@ const makeRequest = ({ url, method, body = null }): Promise<Response> => {
if (body) {
req["body"] = JSON.stringify(body);
}
return fetch(url, req);
return fetch(`${REACT_APP_BACKEND_URL}/${endpoint}`, req);
};
const sendLoginRequest = async (
@@ -17,7 +19,7 @@ const sendLoginRequest = async (
): Promise<object> => {
const p: Promise<object> = new Promise(async (res) => {
await makeRequest({
url: "http://localhost:5000/login",
endpoint: "login",
method: "POST",
body: { username, password },
})
@@ -36,7 +38,7 @@ const sendLoginRequest = async (
const sendLogoutRequest = async (): Promise<object> => {
const p: Promise<object> = new Promise(async (res) => {
await makeRequest({
url: "http://localhost:5000/logout",
endpoint: "logout",
method: "POST",
})
.then((resp) => resp.json())