This commit is contained in:
root
2025-10-17 02:23:24 +00:00
parent 661f7cf6e9
commit efacf59414
8 changed files with 55 additions and 45 deletions

14
.env Normal file
View File

@@ -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"

View File

@@ -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({

View File

@@ -1 +1 @@
VITE_BACKEND_URL="https://livepoll-anjx.onrender.com"
VITE_BACKEND_URL="http://localhost:3000"

View File

@@ -17,15 +17,15 @@ function Header() {
<ul className="menu menu-horizontal px-1 gap-1">
{user.username ? (
<li>
<Link to={"/dashboard"}>Dashboard</Link>
<Link to={"/dashboard"}>仪表盘</Link>
</li>
) : (
<li>
<Link to={"/login"}>Login</Link>
<Link to={"/login"}>登陆</Link>
</li>
)}
<li>
<Link to={"/poll"}>Polls</Link>
<Link to={"/poll"}>投票列表</Link>
</li>
</ul>
</div>

View File

@@ -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",

View File

@@ -3,37 +3,33 @@ import { useNavigate } from 'react-router-dom';
import useStore from '../store/useStore';
function Home() {
const navigator = useNavigate();
return (
<div className="flex bg-base-200 min-h-screen flex-col items-center text-white p-8">
<h1 className="text-4xl mt-2 md:text-5xl font-bold mb-6 text-center flex flex-col gap-2 md:block">Welcome to <span className='bg-slate-800 px-4 rounded-md relative'>LivePoll</span></h1>
<h1 className="text-4xl mt-2 md:text-5xl font-bold mb-6 text-center flex flex-col gap-2 md:block">
欢迎来到 <span className='bg-slate-800 px-4 rounded-md relative'>LivePoll</span>
</h1>
<p className="text-lg text-center max-w-2xl mb-8">
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 是您进行实时互动投票的平台创建投票参与活跃讨论并通过实时更新和可视化获得即时反馈探索人们对您关心话题的看法让您的声音被听到
</p>
<div className="flex flex-col lg:flex-row gap-6 mb-8">
<div className="bg-base-300 p-6 rounded-lg shadow-md w-full lg:w-96 text-center">
<h2 className="text-3xl font-semibold mb-4">Create Polls</h2>
<h2 className="text-3xl font-semibold mb-4">创建投票</h2>
<p className="text-gray-400">
Create custom polls on any topic and share them with others. Add options, set
permissions, and see the responses roll in real-time.
创建关于任何主题的自定义投票并与他人分享添加选项设置权限并实时查看响应结果
</p>
</div>
<div className="bg-base-300 p-6 rounded-lg shadow-md w-full lg:w-96 text-center">
<h2 className="text-3xl font-semibold mb-4">Vote & Participate</h2>
<h2 className="text-3xl font-semibold mb-4">投票与参与</h2>
<p className="text-gray-400">
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.
浏览各种公开投票或加入与您分享的私人投票投出您的一票并在他人参与时查看实时结果
</p>
</div>
<div className="bg-base-300 p-6 rounded-lg shadow-md w-full lg:w-96 text-center">
<h2 className="text-3xl font-semibold mb-4">Bookmark & Track</h2>
<h2 className="text-3xl font-semibold mb-4">收藏与追踪</h2>
<p className="text-gray-400">
Bookmark polls to save them for later, view your past participation, and stay updated
on topics you care about.
收藏投票以便稍后查看查看您过去的参与记录并随时了解您关心的话题动态
</p>
</div>
</div>
@@ -41,7 +37,7 @@ function Home() {
className="btn btn-primary px-6 py-3 font-semibold text-lg"
onClick={() => navigator("/dashboard")}
>
Make a Poll
创建投票
</button>
</div>
)

View File

@@ -41,75 +41,75 @@ const LoginPage = () => {
return (
<div className="flex justify-center bg-base-200 h-screen p-4">
<div className="w-full max-w-md rounded-lg p-8">
<h2 className="text-2xl font-semibold text-center text-white mb-6">Login</h2>
<h2 className="text-2xl font-semibold text-center text-white mb-6">登录</h2>
<form className="space-y-4">
{/* Email Input */}
{/* 邮箱输入 */}
<div className="form-control w-full">
<label className="label">
<span className="label-text text-gray-200">Email</span>
<span className="label-text text-gray-200">邮箱</span>
</label>
<input
type="email"
value={email}
onChange={(e) => 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
/>
</div>
{/* Password Input */}
{/* 密码输入 */}
<div className="form-control w-full">
<label className="label">
<span className="label-text text-gray-200">Password</span>
<span className="label-text text-gray-200">密码</span>
</label>
<input
type="password"
value={password}
onChange={(e) => 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
/>
</div>
{/* Error Message */}
{/* 错误信息 */}
{mutation.isError && <InlineTextError mutation={mutation} />}
{/* Success Message */}
{/* 成功信息 */}
{mutation.isSuccess && (
<p className="text-green-500 text-sm md:text-base">
🎉 {mutation.data.message || "Login is successfull"}
🎉 {mutation.data.message || "登录成功"}
</p>
)}
{/* Forgot Password Link */}
{/* 忘记密码链接 */}
<div className="text-right">
<a href="#" className="text-sm text-primary hover:underline">Forgot password?</a>
<a href="#" className="text-sm text-primary hover:underline">忘记密码</a>
</div>
{/* Submit Button */}
{/* 提交按钮 */}
<div>
<button
onClick={handleLogin}
type="submit"
className="btn btn-primary w-full text-white"
>
{mutation.isLoading ? <SpinnerLoader/> : "Login"}
{mutation.isLoading ? <SpinnerLoader/> : "登录"}
</button>
</div>
</form>
{/* Divider */}
<div className="divider text-gray-400">OR</div>
{/* 分隔符 */}
<div className="divider text-gray-400"></div>
{/* Sign Up Link */}
{/* 注册链接 */}
<p className="text-center text-gray-300">
Dont have an account?{' '}
<Link to="/register" href="#" className="text-primary hover:underline">Sign up</Link>
还没有账户{' '}
<Link to="/register" href="#" className="text-primary hover:underline">立即注册</Link>
</p>
</div>
</div>

View File

@@ -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);
},