diff --git a/.env b/.env new file mode 100644 index 0000000..f339eb3 --- /dev/null +++ b/.env @@ -0,0 +1,14 @@ +# 端口 +PORT=3000 + +# MongoDB 连接地址,如果 MongoDB 在本机默认端口 +DB_CONNECTION="mongodb://localhost:27017/livepoll" + +# 密码加密复杂度 +SALT_ROUNDS=6 + +# JWT 私钥(可以随便写一串随机字符) +JWT_PRIVATE="your-secret-jwt-key" + +# 前端访问地址(群友打开的链接) +CLIENT_URL="http://110.42.109.143:3000" diff --git a/backend/src/controllers/user.controller.js b/backend/src/controllers/user.controller.js index 2e79b80..fb12647 100644 --- a/backend/src/controllers/user.controller.js +++ b/backend/src/controllers/user.controller.js @@ -31,8 +31,8 @@ export async function signinController(req, res) { const { token, userData } = await signinService(email, password); res.cookie("livepoll-access-token", token, { httpOnly: true, - secure: true, - sameSite: "None", + secure: false, + sameSite: "Lax", expires: new Date(Date.now() + 24 * 60 * 60 * 1000 * 365), // 1 year path: "/" }).status(200).json({ diff --git a/frontend/.env b/frontend/.env index d40a145..8c264d6 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1 +1 @@ -VITE_BACKEND_URL="https://livepoll-anjx.onrender.com" \ No newline at end of file +VITE_BACKEND_URL="http://localhost:3000" diff --git a/frontend/src/components/Header/Header.jsx b/frontend/src/components/Header/Header.jsx index 0c3e2ce..4657e8e 100644 --- a/frontend/src/components/Header/Header.jsx +++ b/frontend/src/components/Header/Header.jsx @@ -17,15 +17,15 @@ function Header() { diff --git a/frontend/src/helper/axiosInstance.js b/frontend/src/helper/axiosInstance.js index 9ae963d..24d00de 100644 --- a/frontend/src/helper/axiosInstance.js +++ b/frontend/src/helper/axiosInstance.js @@ -1,8 +1,8 @@ import axios from "axios"; const axiosInstance = axios.create({ - // baseURL: `http://localhost:3000/api/v1`, - baseURL: `https://livepoll-anjx.onrender.com/api/v1`, + baseURL: `http://110.42.109.143:3000/api/v1`, + //baseURL: `https://livepoll-anjx.onrender.com/api/v1`, withCredentials: true, headers: { "Content-Type": "application/json", diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index 9355bd6..b9533a6 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -3,37 +3,33 @@ import { useNavigate } from 'react-router-dom'; import useStore from '../store/useStore'; function Home() { - const navigator = useNavigate(); return (
-

Welcome to LivePoll

+

+ 欢迎来到 LivePoll +

- LivePoll is your platform for real-time, interactive polling. Create polls, participate in - active discussions, and get instant feedback with live updates and visualizations. Discover - what people think on topics that matter to you and have your voice heard! + LivePoll 是您进行实时互动投票的平台。创建投票,参与活跃讨论,并通过实时更新和可视化获得即时反馈。探索人们对您关心话题的看法,让您的声音被听到!

-

Create Polls

+

创建投票

- Create custom polls on any topic and share them with others. Add options, set - permissions, and see the responses roll in real-time. + 创建关于任何主题的自定义投票并与他人分享。添加选项,设置权限,并实时查看响应结果。

-

Vote & Participate

+

投票与参与

- Browse a variety of public polls or join private ones shared with you. Cast your vote - and see the real-time results as others participate. + 浏览各种公开投票或加入与您分享的私人投票。投出您的一票,并在他人参与时查看实时结果。

-

Bookmark & Track

+

收藏与追踪

- Bookmark polls to save them for later, view your past participation, and stay updated - on topics you care about. + 收藏投票以便稍后查看,查看您过去的参与记录,并随时了解您关心的话题动态。

@@ -41,7 +37,7 @@ function Home() { className="btn btn-primary px-6 py-3 font-semibold text-lg" onClick={() => navigator("/dashboard")} > - Make a Poll + 创建投票
) diff --git a/frontend/src/pages/LoginPage.jsx b/frontend/src/pages/LoginPage.jsx index 82ade94..24a9e5a 100644 --- a/frontend/src/pages/LoginPage.jsx +++ b/frontend/src/pages/LoginPage.jsx @@ -41,75 +41,75 @@ const LoginPage = () => { return (
-

Login

+

登录

- {/* Email Input */} + {/* 邮箱输入 */}
setEmail(e.target.value)} - placeholder="Enter your email" + placeholder="请输入您的邮箱" className="input input-bordered w-full bg-gray-700 text-white focus:outline-none focus:ring focus:ring-primary" required />
- {/* Password Input */} + {/* 密码输入 */}
setPassword(e.target.value)} - placeholder="Enter your password" + placeholder="请输入您的密码" className="input input-bordered w-full bg-gray-700 text-white focus:outline-none focus:ring focus:ring-primary" required />
- {/* Error Message */} + {/* 错误信息 */} {mutation.isError && } - {/* Success Message */} + {/* 成功信息 */} {mutation.isSuccess && (

- 🎉 {mutation.data.message || "Login is successfull"} + 🎉 {mutation.data.message || "登录成功"}

)} - {/* Forgot Password Link */} + {/* 忘记密码链接 */}
- Forgot password? + 忘记密码?
- {/* Submit Button */} + {/* 提交按钮 */}
- {/* Divider */} -
OR
+ {/* 分隔符 */} +
- {/* Sign Up Link */} + {/* 注册链接 */}

- Don’t have an account?{' '} - Sign up + 还没有账户?{' '} + 立即注册

diff --git a/frontend/src/pages/VotingPage.jsx b/frontend/src/pages/VotingPage.jsx index f99bbb1..d58430d 100644 --- a/frontend/src/pages/VotingPage.jsx +++ b/frontend/src/pages/VotingPage.jsx @@ -28,8 +28,8 @@ function VotingPage() { const [socket, setSocket] = useState(null); useEffect(() => { - const s = io("https://livepoll-anjx.onrender.com"); - // const s = io("http://localhost:3000"); + // const s = io("https://livepoll-anjx.onrender.com"); + const s = io("http://110.42.109.143:3000"); setSocket(s); s.on("connect", () => { @@ -52,7 +52,7 @@ function VotingPage() { refetch, } = useQuery(["poll", pollId], () => getPollData(pollId), { cacheTime: 10 * 60 * 1000, // 10 minutes - staleTime: 20 * 60 * 1000, // 20 minutes + staleTime: 0, onSuccess: (data) => { setPoll(data); },