Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/src/Pages/ProsConsChallenge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { getAuthToken } from "@/utils/auth";
import { API_BASE_URL } from "@/constants/api";

interface ArgumentEvaluation {
score: number;
Expand Down Expand Up @@ -41,7 +42,7 @@ const ProsConsChallenge: React.FC = () => {
setIsLoading(true);
setError(null);
try {
const response = await fetch("http://localhost:1313/coach/pros-cons/topic", {
const response = await fetch(`${API_BASE_URL}/coach/pros-cons/topic`, {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
Expand Down Expand Up @@ -82,7 +83,7 @@ const ProsConsChallenge: React.FC = () => {
setIsLoading(true);
setError(null);
try {
const response = await fetch("http://localhost:1313/coach/pros-cons/submit", {
const response = await fetch(`${API_BASE_URL}/coach/pros-cons/submit`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/Pages/StrengthenArgument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { API_BASE_URL } from "@/constants/api";
import {
Dialog,
DialogContent,
Expand Down Expand Up @@ -112,7 +113,7 @@ const StrengthenArgument: React.FC = () => {
setError(null);
setWeakStatement(null);
try {
const url = `http://localhost:1313/coach/strengthen-argument/weak-statement?topic=${encodeURIComponent(topic)}&stance=${encodeURIComponent(stance)}`;
const url = `${API_BASE_URL}/coach/strengthen-argument/weak-statement?topic=${encodeURIComponent(topic)}&stance=${encodeURIComponent(stance)}`;
const response = await fetch(url, {
method: "GET",
headers: {
Expand Down Expand Up @@ -152,7 +153,7 @@ const StrengthenArgument: React.FC = () => {
setIsLoading(true);
setError(null);
try {
const response = await fetch("http://localhost:1313/coach/strengthen-argument/evaluate", {
const response = await fetch(`${API_BASE_URL}/coach/strengthen-argument/evaluate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/ChatRoom.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import clsx from 'clsx';
import { WS_BASE_URL } from '../constants/api';

const reactionsList = ['😂', '❤️', '❤️', '👍'];

Expand Down Expand Up @@ -45,7 +46,7 @@ const ChatRoom = () => {
if (!token) return;

wsRef.current = new WebSocket(
`ws://localhost:1313/chat/${roomId}?token=${token}`
`${WS_BASE_URL}/chat/${roomId}?token=${token}`
);

wsRef.current.onopen = () => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/DebatePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { X } from 'lucide-react';
import RoomBrowser from './RoomBrowser';
import Matchmaking from './Matchmaking';
import { API_BASE_URL } from '../constants/api';

interface DebatePopupProps {
onClose: () => void;
Expand All @@ -28,7 +29,7 @@ const DebatePopup: React.FC<DebatePopupProps> = ({ onClose }) => {
try {
// Sending a POST request to create a new room.
// You might also send additional parameters (e.g., room type, settings).
const response = await fetch('http://localhost:1313/rooms', {
const response = await fetch(`${API_BASE_URL}/rooms`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Matchmaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import Avatar from 'react-avatar';
import { useUser } from '../hooks/useUser';
import { WS_BASE_URL } from '../constants/api';

interface MatchmakingPool {
userId: string;
Expand Down Expand Up @@ -59,7 +60,7 @@ const Matchmaking: React.FC = () => {

// Connect to WebSocket with authentication token
const ws = new WebSocket(
`ws://localhost:1313/ws/matchmaking?token=${token}`
`${WS_BASE_URL}/ws/matchmaking?token=${token}`
);
wsRef.current = ws;

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/RoomBrowser.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { API_BASE_URL } from '../constants/api';

interface Participant {
id: string;
Expand All @@ -21,7 +22,7 @@ const RoomBrowser: React.FC = () => {
const fetchRooms = async () => {
const token = localStorage.getItem('token');
try {
const response = await fetch('http://localhost:1313/rooms', {
const response = await fetch(`${API_BASE_URL}/rooms`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -61,7 +62,7 @@ const RoomBrowser: React.FC = () => {
const token = localStorage.getItem('token');
try {
const response = await fetch(
`http://localhost:1313/rooms/${roomId}/join`,
`${API_BASE_URL}/rooms/${roomId}/join`,
{
method: 'POST',
headers: {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/constants/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const API_BASE_URL = (
import.meta.env.VITE_BASE_URL || "http://localhost:1313"
).replace(/\/+$/, "");

export const WS_BASE_URL = API_BASE_URL.replace(/^http/, "ws");