Skip to content

Commit 34d3844

Browse files
committed
ok
1 parent 258ca05 commit 34d3844

7 files changed

Lines changed: 20 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

backend/src/controllers/config.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const url="https://echo-kmn5.onrender.com"
2+
export default url;

frontend/src/components/left-panel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Link, useNavigate } from "react-router-dom";
22
import type { ReactNode } from "react";
3+
import url from "../../../backend/src/controllers/config";
34

45
const Logo = () => (
56
<svg viewBox="0 0 24 24" aria-hidden="true" className="h-8 w-8 text-white fill-current" role="img" aria-label="Echo logo">
@@ -55,7 +56,7 @@ export function LeftPanel({ children }: { children?: ReactNode }) {
5556
{localStorage.getItem('token') ? (
5657
<button onClick={async () => {
5758
try {
58-
await fetch('http://localhost:5000/logout', { method: 'POST', credentials: 'include' });
59+
await fetch(`${url}/logout`, { method: 'POST', credentials: 'include' });
5960
} catch (e) {
6061
// ignore
6162
}

frontend/src/components/main-panel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState, useEffect, useRef, type ReactNode } from "react";
2+
import url from "../../../backend/src/controllers/config";
23

34
interface Post {
45
id: number;
@@ -19,7 +20,7 @@ function ThreeDotMenu({ postId, onDeleted }: { postId: number; onDeleted: () =>
1920
}
2021
if (!confirm("Delete this post?")) return;
2122
try {
22-
const res = await fetch(`http://localhost:5000/post/${postId}`, { method: "DELETE", headers: { Authorization: `Bearer ${token}` } });
23+
const res = await fetch(`${url}/post/${postId}`, { method: "DELETE", headers: { Authorization: `Bearer ${token}` } });
2324
if (res.ok) {
2425
onDeleted();
2526
} else {
@@ -92,7 +93,7 @@ export function MainPanel({ children }: { children?: ReactNode }) {
9293

9394
const fetchPosts = async () => {
9495
try {
95-
const res = await fetch("http://localhost:5000/post");
96+
const res = await fetch(`${url}/post`);
9697
const data = await res.json();
9798
if (data.posts) {
9899
// Reverse to show newest first if the API doesn't sort
@@ -164,7 +165,7 @@ export function MainPanel({ children }: { children?: ReactNode }) {
164165
setLoading(true);
165166
try {
166167
// Using "User" as title since backend requires it
167-
await fetch("http://localhost:5000/post", {
168+
await fetch(`${url}/post`, {
168169
method: "PUT",
169170
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
170171
body: JSON.stringify({ title: "User", body: tweet })

frontend/src/components/profile-panel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type ReactNode, useState, useEffect } from "react";
2-
2+
import url from "../../../backend/src/controllers/config";
33
export function ProfilePanel({ children }: { children?: ReactNode }) {
44
const [open, setOpen] = useState(false);
55
const [email, setEmail] = useState("");
@@ -22,7 +22,7 @@ export function ProfilePanel({ children }: { children?: ReactNode }) {
2222
}
2323

2424
try {
25-
const res = await fetch("http://localhost:5000/profile", {
25+
const res = await fetch(`${url}/profile`, {
2626
method: "PUT",
2727
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
2828
body: JSON.stringify({ email: email || undefined, password: password || undefined, name: name || undefined, bio: bio || undefined, location: location || undefined, website: website || undefined })
@@ -48,7 +48,7 @@ export function ProfilePanel({ children }: { children?: ReactNode }) {
4848
const token = localStorage.getItem('token');
4949
const headers: any = {};
5050
if (token) headers.Authorization = `Bearer ${token}`;
51-
const res = await fetch('http://localhost:5000/profile', { headers });
51+
const res = await fetch(`${url}/profile`, { headers });
5252
if (res.status === 401) {
5353
return false;
5454
}

frontend/src/pages/login.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef, type FormEvent, useState } from "react";
22
import { Link, useNavigate } from "react-router-dom";
3-
3+
import url from "../../../backend/src/controllers/config";
44
export function LoginPage() {
55
const [email, setEmail] = useState("");
66
const [password, setPassword] = useState("");
@@ -11,15 +11,17 @@ export function LoginPage() {
1111
e.preventDefault();
1212
setLoading(true);
1313
try {
14-
const res = await fetch("http://localhost:5000/login", {
14+
const res = await fetch(`${url}/login`, {
1515
method: "POST",
1616
headers: { "Content-Type": "application/json" },
1717
body: JSON.stringify({ email, password })
1818
});
1919
if (res.ok) {
2020
const data = await res.json();
21-
if (data.token) {
22-
localStorage.setItem("token", data.token);
21+
// backend returns { accessToken }, but older clients expect { token }
22+
const token = data.token ?? data.accessToken;
23+
if (token) {
24+
localStorage.setItem("token", token);
2325
navigate("/");
2426
return;
2527
}

frontend/src/pages/signup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from "react";
22
import { useNavigate } from "react-router-dom";
3+
import url from "../../../backend/src/controllers/config";
34

45
export function SignupPage() {
56
const [email, setEmail] = useState("");
@@ -11,7 +12,7 @@ export function SignupPage() {
1112
e.preventDefault();
1213
setLoading(true);
1314
try {
14-
const res = await fetch("http://localhost:5000/signup", {
15+
const res = await fetch(`${url}/signup`, {
1516
method: "POST",
1617
headers: { "Content-Type": "application/json" },
1718
body: JSON.stringify({ email, password })

0 commit comments

Comments
 (0)