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
3 changes: 0 additions & 3 deletions backend/.env

This file was deleted.

1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_API_BASE_URL=https://stackit-etwq.onrender.com
3 changes: 2 additions & 1 deletion frontend/src/components/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
import { Link, useSearchParams, useNavigate } from 'react-router-dom';
import axios from 'axios';
import './Questions.css';
import api from '../index';

const Questions = () => {
const [questions, setQuestions] = useState([]);
Expand Down Expand Up @@ -51,7 +52,7 @@ const Questions = () => {
url += `&search=${encodeURIComponent(search)}`;
}

const res = await axios.get(url);
const res = await api.get(url);

if (res.data.success) {
setQuestions(res.data.questions);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import axios from 'axios';
import api from '../index';

const Profile = () => {
const navigate = useNavigate();
Expand All @@ -24,7 +25,7 @@ const Profile = () => {
}
};

const res = await axios.get('/api/auth/me', config);
const res = await api.get('/auth/me', config);

if (res.data.success) {
setUser(res.data.user);
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/QuestionDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
import { Paper, Card, Box, Typography, Button, Chip, Alert, Divider } from '@mui/material';
import { styled } from '@mui/material/styles';
import api from '../index';

const QuestionDetail = () => {
const { id } = useParams();
Expand All @@ -31,7 +32,7 @@ const QuestionDetail = () => {
setLoading(true);
setError('');
try {
const res = await axios.get(`/api/questions/${id}`);
const res = await api.get(`/questions/${id}`);
if (res.data.success) {
setQuestion(res.data.question);
} else {
Expand Down Expand Up @@ -63,11 +64,11 @@ const QuestionDetail = () => {
}
};
const body = JSON.stringify({ description: answerText });
const res = await axios.post(`/api/answers/${id}`, body, config);
const res = await api.post(`/answers/${id}`, body, config);
if (res.data.success) {
setAnswerText('');
// Refresh question to show new answer
const updated = await axios.get(`/api/questions/${id}`);
const updated = await api.get(`/questions/${id}`);
setQuestion(updated.data.question);
}
} catch (err) {
Expand All @@ -92,7 +93,7 @@ const QuestionDetail = () => {
}
};
const body = { type };
const res = await axios.post(`/api/answers/${answerId}/vote`, body, config);
const res = await api.post(`/answers/${answerId}/vote`, body, config);
if (res.data.success !== false) {
// Update the answer's vote count in local state instantly
setQuestion(prev => {
Expand Down Expand Up @@ -136,7 +137,7 @@ const QuestionDetail = () => {
}
};
const body = JSON.stringify({ text });
const res = await axios.post(`/api/answers/${answerId}/comments`, body, config);
const res = await api.post(`/answers/${answerId}/comments`, body, config);
if (res.data.success) {
setQuestion(prev => {
if (!prev) return prev;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/SignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@mui/material';
import { Link, useNavigate } from 'react-router-dom';
import axios from 'axios';
import api from '../index';

const SignIn = () => {
const navigate = useNavigate();
Expand All @@ -29,7 +30,7 @@ const SignIn = () => {

try {
const config = { headers: { 'Content-Type': 'application/json' } };
const res = await axios.post('/api/auth/login', JSON.stringify(formData), config);
const res = await api.post('/auth/login', JSON.stringify(formData), config);

if (res.data.success) {
localStorage.setItem('token', res.data.token);
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import axios from 'axios';

const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
});

export default api;

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
Expand Down