Spaces:
Running
Running
Download server.js from bravo09/brainboost-academy: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/spaces/bravo09/brainboost-academy/resolve/main/server.js
- Command line
-
hf download hf://spaces/bravo09/brainboost-academy/server.js
-
curl -L -o server.js https://huggingface.co/spaces/bravo09/brainboost-academy/resolve/main/server.js
1.52 kB
| require('dotenv').config(); | |
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const cors = require('cors'); | |
| const cookieParser = require('cookie-parser'); | |
| const path = require('path'); | |
| // Initialize Express app | |
| const app = express(); | |
| // Middleware | |
| app.use(cors({ | |
| origin: process.env.FRONTEND_URL || 'http://localhost:3000', | |
| credentials: true | |
| })); | |
| app.use(express.json()); | |
| app.use(cookieParser()); | |
| app.use(express.static(path.join(__dirname, 'public'))); | |
| // Database connection | |
| mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/brainboost', { | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true | |
| }) | |
| .then(() => console.log('Connected to MongoDB')) | |
| .catch(err => console.error('MongoDB connection error:', err)); | |
| // Routes | |
| app.use('/api/auth', require('./routes/auth')); | |
| app.use('/api/courses', require('./routes/courses')); | |
| app.use('/api/camps', require('./routes/camps')); | |
| app.use('/api/users', require('./routes/users')); | |
| // Serve frontend in production | |
| if (process.env.NODE_ENV === 'production') { | |
| app.use(express.static(path.join(__dirname, '../frontend/dist'))); | |
| app.get('*', (req, res) => { | |
| res.sendFile(path.join(__dirname, '../frontend/dist/index.html')); | |
| }); | |
| } | |
| // Error handling middleware | |
| app.use((err, req, res, next) => { | |
| console.error(err.stack); | |
| res.status(500).json({ message: 'Something went wrong!' }); | |
| }); | |
| // Start server | |
| const PORT = process.env.PORT || 5000; | |
| app.listen(PORT, () => { | |
| console.log(`Server running on port ${PORT}`); | |
| }); |