Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved merge conflicts #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const express = require("express");
const connectDB = require("./config/database");
const authRoutes = require("./routes/auth");
const noteRoutes = require("./routes/notes");

const cors = require('cors');
const rateLimit = require('express-rate-limit');
const app = express();

// Connect to MongoDB
Expand All @@ -15,4 +16,37 @@ app.use(express.json());
app.use("/api/auth", authRoutes);
app.use("/api/notes", noteRoutes);

// CORS Middleware Setup
const corsOptions = {
origin: ['*'],
allowedHeaders: ['Content-Type', 'Authorization'],
optionsSuccessStatus: 200
};

app.use(cors(corsOptions));

// Rate Limiting Setup
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per windowMs
message: "Too many requests from this IP, please try again after 15 minutes."
});

app.use(limiter);

// Routes
app.get('/', (req, res) => {
res.send('Welcome to the API!');
});

app.post('/data', (req, res) => {
res.json({ message: 'This is a POST request response' });
});

// Start the Server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});

module.exports = app;
Loading