Skip to content

Commit 70a5d89

Browse files
committed
use env variable for api calls
1 parent a9534db commit 70a5d89

File tree

8 files changed

+59
-49
lines changed

8 files changed

+59
-49
lines changed

client/src/components/task_form.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function TaskForm({ userId, onTaskCreated }: TaskFormProps) {
4343
const [availableTopics, setAvailableTopics] = useState<Topic[]>([]);
4444

4545
useEffect(() => {
46-
fetch("http://localhost:8000/api/planner/topic/")
46+
fetch(process.env.NEXT_PUBLIC_BACKEND_URL + "planner/topic/")
4747
.then((res) => res.json())
4848
.then((data) => setAvailableTopics(data))
4949
.catch((err) => console.error("Failed to load topics:", err));
@@ -66,22 +66,25 @@ export function TaskForm({ userId, onTaskCreated }: TaskFormProps) {
6666
const new_topics = topics
6767
.filter((t) => t.type === "new")
6868
.map((t) => ({ name: t.name, color_hex: t.color_hex }));
69-
const response = await fetch("http://localhost:8000/api/planner/tasks/", {
70-
method: "POST",
71-
headers: {
72-
"Content-Type": "application/json",
73-
Authorization: `Bearer ${token}`,
69+
const response = await fetch(
70+
process.env.NEXT_PUBLIC_BACKEND_URL + "planner/tasks/",
71+
{
72+
method: "POST",
73+
headers: {
74+
"Content-Type": "application/json",
75+
Authorization: `Bearer ${token}`,
76+
},
77+
body: JSON.stringify({
78+
name: taskName,
79+
description: description,
80+
completed: false,
81+
user_id: userId,
82+
times: times,
83+
existing_topic_ids: existing_topic_ids,
84+
new_topics: new_topics,
85+
}),
7486
},
75-
body: JSON.stringify({
76-
name: taskName,
77-
description: description,
78-
completed: false,
79-
user_id: userId,
80-
times: times,
81-
existing_topic_ids: existing_topic_ids,
82-
new_topics: new_topics,
83-
}),
84-
});
87+
);
8588

8689
if (!response.ok) {
8790
throw new Error("Failed to create task");

client/src/components/task_item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function TaskItem({
9898
}));
9999

100100
const response = await fetch(
101-
`http://localhost:8000/api/planner/tasks/${item.id}/`,
101+
process.env.NEXT_PUBLIC_BACKEND_URL + `planner/tasks/${item.id}/`,
102102
{
103103
method: "PUT",
104104
headers: {
@@ -234,7 +234,7 @@ export function TaskItem({
234234

235235
<div className="task-edit flex gap-2">
236236
{isEditing ? (
237-
<div className="flex w-full flex-row justify-center text-lg gap-2">
237+
<div className="flex w-full flex-row justify-center gap-2 text-lg">
238238
<button
239239
className="rounded-full bg-indigo-400 px-3 py-1 hover:brightness-110"
240240
onClick={saveEdit}

client/src/pages/focus.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const CountdownTimer = () => {
5252
return;
5353
}
5454
const auth = await fetch(
55-
"http://localhost:8000/api/planner/protected/",
55+
process.env.NEXT_PUBLIC_BACKEND_URL + "planner/protected/",
5656
{
5757
headers: {
5858
Authorization: `Bearer ${token}`,
@@ -64,7 +64,7 @@ const CountdownTimer = () => {
6464
return;
6565
}
6666
const tasksFetch = await fetch(
67-
`http://localhost:8000/api/planner/tasks/`,
67+
process.env.NEXT_PUBLIC_BACKEND_URL + "planner/tasks/",
6868
{
6969
headers: {
7070
Authorization: `Bearer ${token}`,

client/src/pages/login.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ export default function Login() {
1313

1414
const formData = new FormData(e.currentTarget);
1515

16-
const res = await fetch("http://127.0.0.1:8000/api/auth/login/", {
17-
method: "POST",
18-
headers: {
19-
"Content-Type": "application/json",
16+
const res = await fetch(
17+
process.env.NEXT_PUBLIC_BACKEND_URL + "auth/login/",
18+
{
19+
method: "POST",
20+
headers: {
21+
"Content-Type": "application/json",
22+
},
23+
body: JSON.stringify({
24+
username: formData.get("username"),
25+
email: formData.get("email"),
26+
password: formData.get("password"),
27+
}),
2028
},
21-
body: JSON.stringify({
22-
username: formData.get("username"),
23-
email: formData.get("email"),
24-
password: formData.get("password"),
25-
}),
26-
});
29+
);
2730

2831
const data = await res.json();
2932
if (!res.ok) {
@@ -37,7 +40,7 @@ export default function Login() {
3740
const token = localStorage.getItem("access");
3841

3942
const userFetch = await fetch(
40-
"http://127.0.0.1:8000/api/planner/protected",
43+
process.env.NEXT_PUBLIC_BACKEND_URL + "planner/protected",
4144
{
4245
headers: {
4346
Authorization: `Bearer ${token}`,

client/src/pages/register.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ export default function Register() {
1111
e.preventDefault();
1212
const formData = new FormData(e.currentTarget);
1313

14-
const res = await fetch("http://127.0.0.1:8000/api/planner/register/", {
15-
method: "POST",
16-
headers: { "Content-Type": "application/json" },
17-
body: JSON.stringify({
18-
username: formData.get("username"),
19-
email: formData.get("email"),
20-
password: formData.get("password"),
21-
}),
22-
});
14+
const res = await fetch(
15+
process.env.NEXT_PUBLIC_BACKEND_URL + "planner/register/",
16+
{
17+
method: "POST",
18+
headers: { "Content-Type": "application/json" },
19+
body: JSON.stringify({
20+
username: formData.get("username"),
21+
email: formData.get("email"),
22+
password: formData.get("password"),
23+
}),
24+
},
25+
);
2326

2427
const data = await res.json();
2528
if (!res.ok) {

client/src/pages/schedule.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function Schedule() {
9191
return;
9292
}
9393
const auth = await fetch(
94-
"http://localhost:8000/api/planner/protected/",
94+
process.env.NEXT_PUBLIC_BACKEND_URL + "planner/protected/",
9595
{
9696
headers: {
9797
Authorization: `Bearer ${token}`,
@@ -103,7 +103,7 @@ function Schedule() {
103103
return;
104104
}
105105
const tasksFetch = await fetch(
106-
`http://localhost:8000/api/planner/tasks/`,
106+
process.env.NEXT_PUBLIC_BACKEND_URL + `planner/tasks/`,
107107
{
108108
headers: {
109109
Authorization: `Bearer ${token}`,

client/src/pages/tasks.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function TasksPage() {
4949
return;
5050
}
5151
const auth = await fetch(
52-
"http://localhost:8000/api/planner/protected/",
52+
process.env.NEXT_PUBLIC_BACKEND_URL + "planner/protected/",
5353
{
5454
headers: {
5555
Authorization: `Bearer ${token}`,
@@ -64,7 +64,7 @@ export default function TasksPage() {
6464
const user = await auth.json();
6565
setUserId(user.user_id);
6666
const tasksFetch = await fetch(
67-
`http://localhost:8000/api/planner/tasks/`,
67+
process.env.NEXT_PUBLIC_BACKEND_URL + `planner/tasks/`,
6868
{
6969
headers: {
7070
Authorization: `Bearer ${token}`,
@@ -84,7 +84,7 @@ export default function TasksPage() {
8484
}, [router]);
8585

8686
useEffect(() => {
87-
fetch("http://localhost:8000/api/planner/topic/")
87+
fetch(process.env.NEXT_PUBLIC_BACKEND_URL + "planner/topic/")
8888
.then((res) => res.json())
8989
.then((data) => setAvailableTopics(data))
9090
.catch((err) => console.error("Failed to load topics", err));
@@ -106,7 +106,8 @@ export default function TasksPage() {
106106

107107
try {
108108
const response = await fetch(
109-
`http://localhost:8000/api/planner/tasks/${id}/toggle_complete/`,
109+
process.env.NEXT_PUBLIC_BACKEND_URL +
110+
`planner/tasks/${id}/toggle_complete/`,
110111
{
111112
method: "PATCH",
112113
headers: {
@@ -142,7 +143,7 @@ export default function TasksPage() {
142143

143144
try {
144145
const response = await fetch(
145-
`http://localhost:8000/api/planner/tasks/${id}/`,
146+
process.env.NEXT_PUBLIC_BACKEND_URL + `planner/tasks/${id}/`,
146147
{
147148
method: "DELETE",
148149
headers: {

docker-compose.prod.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
retries: 5
1313

1414
server:
15-
image: ghcr.io/codersforcauses/django-nextjs-template-use_uv-prod-server:latest
15+
image: ghcr.io/codersforcauses/intermediate_team_3-use_uv-prod-server:latest
1616
container_name: transplant_server
1717
restart: unless-stopped
1818
env_file: ./.env.prod
@@ -28,7 +28,7 @@ services:
2828
- db
2929

3030
client:
31-
image: ghcr.io/codersforcauses/django-nextjs-template-use_uv-prod-client:latest
31+
image: ghcr.io/codersforcauses/intermediate_team_3-use_uv-prod-client:latest
3232
container_name: transplant_client
3333
restart: unless-stopped
3434
env_file: ./.env.prod

0 commit comments

Comments
 (0)