pref: 去除开发环境配置

This commit is contained in:
zdl
2025-10-16 15:54:52 +08:00
parent ca51252fce
commit 081eb3c5c3
6 changed files with 42 additions and 57 deletions

View File

@@ -42,9 +42,6 @@ import { format } from 'date-fns';
import { zhCN } from 'date-fns/locale';
import { eventService } from '../../../services/eventService';
// 获取 API 基础地址
const API_BASE_URL = process.env.NODE_ENV === 'production' ? '' : (process.env.REACT_APP_API_URL || 'http://49.232.185.254:5001');
const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussionType = '事件讨论' }) => {
const [posts, setPosts] = useState([]);
const [newPostContent, setNewPostContent] = useState('');
@@ -67,7 +64,7 @@ const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussion
setLoading(true);
try {
const response = await fetch(`${API_BASE_URL}/api/events/${eventId}/posts?sort=latest&page=1&per_page=20`, {
const response = await fetch(`/api/events/${eventId}/posts?sort=latest&page=1&per_page=20`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
@@ -101,7 +98,7 @@ const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussion
const loadPostComments = async (postId) => {
setLoadingComments(prev => ({ ...prev, [postId]: true }));
try {
const response = await fetch(`${API_BASE_URL}/api/posts/${postId}/comments?sort=latest`, {
const response = await fetch(`/api/posts/${postId}/comments?sort=latest`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
@@ -134,7 +131,7 @@ const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussion
setSubmitting(true);
try {
const response = await fetch(`${API_BASE_URL}/api/events/${eventId}/posts`, {
const response = await fetch(`/api/events/${eventId}/posts`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
@@ -182,7 +179,7 @@ const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussion
if (!window.confirm('确定要删除这个帖子吗?')) return;
try {
const response = await fetch(`${API_BASE_URL}/api/posts/${postId}`, {
const response = await fetch(`/api/posts/${postId}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
@@ -219,7 +216,7 @@ const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussion
// 点赞帖子
const handleLikePost = async (postId) => {
try {
const response = await fetch(`${API_BASE_URL}/api/posts/${postId}/like`, {
const response = await fetch(`/api/posts/${postId}/like`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
@@ -251,7 +248,7 @@ const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussion
if (!content?.trim()) return;
try {
const response = await fetch(`${API_BASE_URL}/api/posts/${postId}/comments`, {
const response = await fetch(`/api/posts/${postId}/comments`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
@@ -294,7 +291,7 @@ const EventDiscussionModal = ({ isOpen, onClose, eventId, eventTitle, discussion
if (!window.confirm('确定要删除这条评论吗?')) return;
try {
const response = await fetch(`${API_BASE_URL}/api/comments/${commentId}`, {
const response = await fetch(`/api/comments/${commentId}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'