Download server.js from denismorris/projectpurity-proctor: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/spaces/denismorris/projectpurity-proctor/resolve/main/server.js
- Command line
-
hf download hf://spaces/denismorris/projectpurity-proctor/server.js
-
curl -L -o server.js https://huggingface.co/spaces/denismorris/projectpurity-proctor/resolve/main/server.js
1.53 kB
| require('dotenv').config(); | |
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const cors = require('cors'); | |
| const helmet = require('helmet'); | |
| const rateLimit = require('express-rate-limit'); | |
| const morgan = require('morgan'); | |
| const path = require('path'); | |
| const app = express(); | |
| // Middleware | |
| app.use(cors()); | |
| app.use(helmet()); | |
| app.use(express.json()); | |
| app.use(express.urlencoded({ extended: true })); | |
| app.use(morgan('dev')); | |
| // Rate limiting | |
| const limiter = rateLimit({ | |
| windowMs: 15 * 60 * 1000, // 15 minutes | |
| max: 100 // limit each IP to 100 requests per windowMs | |
| }); | |
| app.use(limiter); | |
| // Database connection | |
| mongoose.connect(process.env.MONGODB_URI, { | |
| 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/projects', require('./routes/projects')); | |
| app.use('/api/users', require('./routes/users')); | |
| // Serve static files in production | |
| if (process.env.NODE_ENV === 'production') { | |
| app.use(express.static(path.join(__dirname, 'public'))); | |
| app.get('*', (req, res) => { | |
| res.sendFile(path.join(__dirname, 'public', 'index.html')); | |
| }); | |
| } | |
| // Error handling | |
| app.use((err, req, res, next) => { | |
| console.error(err.stack); | |
| res.status(500).json({ error: 'Something went wrong!' }); | |
| }); | |
| const PORT = process.env.PORT || 5000; | |
| app.listen(PORT, () => { | |
| console.log(`Server running on port ${PORT}`); | |
| }); |