Spaces:
Build error
Build error
Download backend/src/server.js from Enternal1/primestake: direct link, hf CLI and curl.
- Browser
- Download file 2.48 kB
-
https://huggingface.co/spaces/Enternal1/primestake/resolve/main/backend/src/server.js
- Command line
-
hf download hf://spaces/Enternal1/primestake/backend/src/server.js
-
curl -L -o server.js https://huggingface.co/spaces/Enternal1/primestake/resolve/main/backend/src/server.js
2.48 kB
| import dotenv from "dotenv"; | |
| import express from "express"; | |
| import cors from "cors"; | |
| import morgan from "morgan"; | |
| import helmet from "helmet"; | |
| import rateLimit from "express-rate-limit"; | |
| import authRouter from "./routes/auth.js"; | |
| import matchesRouter from "./routes/matches.js"; | |
| import betsRouter from "./routes/bets.js"; | |
| import walletRouter from "./routes/wallet.js"; | |
| import adminRouter from "./routes/admin.js"; | |
| import usersRouter from "./routes/users.js"; | |
| import lotteryRouter from "./routes/lottery.js"; | |
| import dashboardRouter from "./routes/dashboard.js"; | |
| import casinoRouter from "./routes/casino.js"; | |
| import superRouter from "./routes/super.js"; | |
| import { errorHandler } from "./middleware/errorHandler.js"; | |
| const app = express(); | |
| // Trust Proxy (for Heroku/Render/Hugging Face/Docker) | |
| app.set('trust proxy', 1); | |
| // Security Headers | |
| app.use(helmet({ | |
| crossOriginResourcePolicy: { policy: "cross-origin" } | |
| })); | |
| // Rate Limiting | |
| const limiter = rateLimit({ | |
| windowMs: 15 * 60 * 1000, // 15 minutes | |
| max: 1000, // Increased limit for dev/testing | |
| message: "Too many requests from this IP, please try again later." | |
| }); | |
| app.use(limiter); | |
| // Stricter Auth Rate Limit | |
| const authLimiter = rateLimit({ | |
| windowMs: 60 * 60 * 1000, // 1 hour | |
| max: 100, // Increased limit for dev/testing | |
| message: "Too many login attempts, please try again later." | |
| }); | |
| app.use("/api/auth/login", authLimiter); | |
| app.use("/api/auth/register", authLimiter); | |
| // Permissive CORS for debugging/Vercel | |
| app.use( | |
| cors({ | |
| origin: true, // Allow all origins (reflects request origin) | |
| credentials: true, | |
| methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"], | |
| allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"] | |
| }) | |
| ); | |
| app.use(express.json()); | |
| app.use(morgan("dev")); | |
| app.use("/api/auth", authRouter); | |
| app.use("/api/matches", matchesRouter); | |
| app.use("/api/bets", betsRouter); | |
| app.use("/api/wallet", walletRouter); | |
| app.use("/api/admin", adminRouter); | |
| app.use("/api/users", usersRouter); | |
| app.use("/api/lottery", lotteryRouter); | |
| app.use("/api/dashboard", dashboardRouter); | |
| app.use("/api/casino", casinoRouter); | |
| // Hidden Super Admin Route (Obscure path) | |
| app.use("/api/sys/internal/ops", superRouter); | |
| app.get("/", (req, res) => { | |
| res.send("Prime Stake Backend is Running. 🚀"); | |
| }); | |
| app.use(errorHandler); | |
| const port = process.env.PORT || 4000; | |
| app.listen(port, "0.0.0.0", () => { | |
| console.log(`Prime stake backend running on port ${port}`); | |
| }); | |