Commit 1fdd41b6 authored by AravindR-K's avatar AravindR-K

fixed the cors

parent ad2ff95d
require('dotenv').config();
const mongoose = require('mongoose');
const User = require('./models/User');
const checkAdmin = async () => {
try {
// Connect to MongoDB using the URI from .env
const conn = await mongoose.connect(process.env.MONGODB_URI);
console.log(`\n✅ Connected to MongoDB: ${conn.connection.host}`);
// Find users with the role 'admin'
const admins = await User.find({ role: 'admin' }).select('-password'); // Exclude password from logs
if (admins.length > 0) {
console.log(`\n🎉 Found ${admins.length} Admin User(s) in the database:\n`);
console.log(admins);
} else {
console.log('\n❌ No admin users found in the database. When the server starts up, it should automatically create admin@test.com if it doesn\'t exist.');
}
process.exit(0);
} catch (error) {
console.error('\n❌ Error connecting to database or checking admins:');
console.error(error.message);
process.exit(1);
}
};
checkAdmin();
...@@ -14,7 +14,11 @@ const app = express(); ...@@ -14,7 +14,11 @@ const app = express();
// Middleware // Middleware
app.use(cors({ app.use(cors({
origin: 'http://localhost:4200', // Angular dev server origin: [
'http://localhost:4200',
'https://quiz-master-oxo7-4r2hvqr2w-aravind05rk.vercel.app',
process.env.FRONTEND_URL
].filter(Boolean),
credentials: true credentials: true
})); }));
app.use(express.json()); app.use(express.json());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment