-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (28 loc) · 1.06 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const rateLimit = require('express-rate-limit');
// Replace with your MongoDB connection string
const mongoDBUrl = process.env.MONGODB_URI;
mongoose.connect(mongoDBUrl, { useNewUrlParser: true, useUnifiedTopology: true });
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
db.once('open', () => {
console.log('Connected to MongoDB');
});
const app = express();
app.use(cors());
app.use(express.json());
const authLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 25, // limit each IP to 5 requests per windowMs
message: 'Too many requests from this IP, please try again after 15 minutes',
});
// Import and use the authentication routes
const authRoutes = require('./routes/authRoutes');
app.use('/', authLimiter, authRoutes);
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Authentication service running on port ${PORT}`);
});