Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloa2025 committed Mar 17, 2024
1 parent 2d9dd34 commit dd2d76c
Show file tree
Hide file tree
Showing 8 changed files with 11,943 additions and 9,641 deletions.
16 changes: 16 additions & 0 deletions meetdigest/backend/Routes/MeetData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express =require('express')
const router=express.Router()

router.post('/meetinfo',(req,res)=>
{
try {
console.log('Meet Data:', global.meetdata);

res.send([global.meetdata]);

} catch (error) {
console.error(error.message);
res.send("Sever Error")
}
})
module.exports=router;
51 changes: 51 additions & 0 deletions meetdigest/backend/dbmeet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// const mongoose =require('mongoose');
// const mongoURI="mongodb+srv://kaloa2025:[email protected]/hackhive?retryWrites=true&w=majority&appName=Cluster0";
// const mongoDB = async () => {
// try {
// await mongoose.connect(mongoURI);
// console.log('Connected!');

// const fetched_data = mongoose.connection.db.collection("meetdata");
// const data = await fetched_data.find({}).toArray();
// global.meet = data;
// console.log('Data fetched and stored successfully.');
// } catch (error) {
// console.log('err: ', error);
// }
// };
// module.exports=mongoDB;

// const mongoose = require('mongoose');
// const mongoURI = "mongodb+srv://kaloa2025:[email protected]/hackhive?retryWrites=true&w=majority&appName=Cluster0";

// const connectDB = async () => {
// try {
// await mongoose.connect(mongoURI, {
// useNewUrlParser: true,
// useUnifiedTopology: true
// });
// console.log('Connected to MongoDB');
// } catch (error) {
// console.error('MongoDB connection error:', error);
// process.exit(1); // Exit process with failure
// }
// };

console.log("starting")
const mongoose =require('mongoose');
const mongoURI='mongodb://localhost:27017/hackhive';
// const mongoURI='mongodb+srv://kaloa2025:[email protected]/hackhive?retryWrites=true&w=majority&appName=Cluster0';
const mongoDB = () => {
try {
mongoose.connect(mongoURI);
console.log('Connected!');
const meet=require('./models/Meet');
const fetched_data = mongoose.connection.db.collection('meets');
const mdata = fetched_data.find({}).toArray();
global.meetdata = mdata;
console.log('Data fetched and stored successfully.');
}catch(error){
console.log('err: ', error);
}
};
module.exports=mongoDB;
95 changes: 95 additions & 0 deletions meetdigest/backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// const express=require('express')
// const app = express()
// var cors=require('cors');

// const port =5000
// const mongoDB=require('./db')
// mongoDB();
// app.use((req,res,next)=>{
// res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
// res.setHeader('Access-Control-Allow-Methods', 'POST');
// res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
// next();
// })
// app.get('/',(req,res)=>
// {
// res.send("Hello")
// })
// app.use(cors());
// app.use(express.json())
// app.use('/api', require('./Routes/MeetInfo'));
// app.listen(port,()=>
// {
// console.log(`Example listening on ${port}`)
// })

// const express = require('express');
// const cors = require('cors');
// const mongoose=require('mongoose')
// const connectDB = require('./db');
// const meetInfoRoutes = require('./Routes/MeetData');

// const app = express();
// const port = 5000;

// // Connect to MongoDB
// connectDB();

// // Middleware
// app.use(cors());
// app.use(express.json());

// // Routes
// app.use('/api', meetInfoRoutes);

// // Start server
// app.listen(port, () => {
// console.log(`Server is running on port ${port}`);
// // });

// const express=require('express')
// const mongoose=require('mongoose')
// const cors=require('cors')
// const MeetModel =require('./models/Meet')
// const app=express()
// app.use(cors());
// app.use(express.json());

// mongoose.connect("mongodb+srv://kaloa2025:[email protected]/hackhive?retryWrites=true&w=majority&appName=Cluster0")

// app.get('/getMeet',(req,res)=>{
// MeetModel.find().then(meetData=>res.json(meetData)).catch(err=>res.json(err))
// })

// app.listen(3000,()=>{
// console.log("Sever listening");
// })




const express=require('express')
const app = express()
var cors=require('cors');

const port =5000
const mongoDB=require('./dbmeet')
mongoDB();
app.use((req,res,next)=>{
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Methods', 'GET');
res.setHeader('Access-Control-Allow-Methods', 'POST');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
next();
})
app.get('/',(req,res)=>
{
res.send("Hello")
})
app.use(cors());
app.use(express.json())
app.use('/api',require('./Routes/MeetData'));
app.listen(port,()=>
{
console.log(`Example listening on ${port}`)
})
9 changes: 9 additions & 0 deletions meetdigest/backend/models/Meet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mongoose=require('mongoose')
const{ Schema }=mongoose;

const MeetSchema = new mongoose.Schema({
id: String,
title: String,
date: String
});
module.exports=mongoose.model('Meet',MeetSchema)
Loading

0 comments on commit dd2d76c

Please sign in to comment.