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

website deployed #35

Open
wants to merge 5 commits into
base: main
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
7 changes: 7 additions & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
JWT_SECRET = "helloiamsudhanshuprasad"
PORT = "5000"
MONGO_URI = "mongodb://localhost:27017/College-Canteen?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false"
MONGOURI = "mongodb+srv://sudhanshuprasad:[email protected]/College-Canteen"
GOOGLE_CLIENT_ID = "1043021312598-e45htjk65efnmf3jg3ei2dgca6qcmq3f.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET = "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"
BACKEND_URL = "http://localhost:5000"
1 change: 1 addition & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
14 changes: 14 additions & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const mongoose = require('mongoose');

// console.log("mongo uri = "+process.env.MONGO_URI);
const connectToMongo = ()=>{
mongoose.connect(process.env.MONGO_URI, (err)=>{
if(err){
console.log(err);
}else{
console.log("Connected to mongoose");
}
})
}

module.exports=connectToMongo;
59 changes: 59 additions & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// const fetch = require('node-fetch');

const http=require('http');
const connectToMongo = require('./db');
const dotenv=require('dotenv').config();
const cookieSession = require("cookie-session");
// const passportConfig = require("./passportConfig");
// const passport_auth = require("./routes/passport-auth");
// const passport = require("passport");

connectToMongo();

const express = require('express')
const app = express();
const port = process.env.PORT||5000

const cors = require('cors');
const res = require('express/lib/response');
const { contentType, json } = require('express/lib/response');
const { application } = require('express');
const { hostname } = require('os');
const cookieParser = require('cookie-parser');
app.use(
cors({
origin: "*",
allowedHeaders: "*"
})
)

app.use(
cookieSession({ name: "session", keys: [process.env.JWT_SECRET], maxAge: 24 * 60 * 60 * 100 })
);

app.use(express.json());
// app.use(passport.initialize());
// app.use(passport.session());
app.use(cookieParser())
// app.use(passport_auth);

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end('Hello World');
});

app.get('/',(req,res)=>{
res.send("backend is working")
})

app.use('/api/auth', require('./routes/auth'));
app.use('/api/cart', require('./routes/cart'));
app.use('/api/fooditem', require('./routes/fooditem'));
app.use('/api/order', require('./routes/order'));
// app.use('/api/passport-auth', require('./routes/passport-auth'));

app.listen(port,() => {
console.log(`Canteen app listening on port ${port}`)
})

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const jwt = require('jsonwebtoken');

const fetchUser = (req, res, next) => {
//Get the user from the jwt token and add ID to req object
const token = req.header('authToken');
if(token!=null){
// console.log("token= "+token)
}
//if token == null, neeche wala if k andar ka code execute nahi ho raha hai
if (!token) {
res.status(401).send({ error: "No Token Please authenticate using a valid token" });
return;
}
try {
const data = jwt.verify(token, process.env.JWT_SECRET);
req.user = data.user;
if(data.user==undefined){
res.status(500).send("Internal server error");
return;
}
} catch (error) {
res.status(401).send({ error: "Please authenticate using a valid token" });
return;
}
next();
}


module.exports = fetchUser;
22 changes: 22 additions & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/models/Cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { default: mongoose } = require("mongoose");
const req = require("mongoose");
const { Schema } = mongoose;

const CartSchema = new Schema({
user:{
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'user'
},
items:{
type: Array,
required: true
},
timestamp:{
type: String,
required: true,
default: Date.now
}
});

module.exports = mongoose.model('cart', CartSchema);
32 changes: 32 additions & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/models/Fooditem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { default: mongoose } = require("mongoose");
const req = require("mongoose");
const { Schema } = mongoose;

const FoodSchema = new Schema({
// id:{
// type: mongoose.Schema.Types.ObjectId,
// required: true,
// ref: 'user'
// },
imageurl:{
type:String
},
name:{
type: String,
required: true
},
shopName:{
type: String,
required: true
},
price:{
type:Number,
required:true
},
dsc:{
type: String,
required: true,
}
});

module.exports = mongoose.model('food', FoodSchema);
22 changes: 22 additions & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/models/Order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { default: mongoose } = require("mongoose");
const req = require("mongoose");
const { Schema } = mongoose;

const OrderSchema = new Schema({
user:{
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'user'
},
items:{
type: Array,
required: true
},
timestamp:{
type: String,
required: true,
default: Date.now
}
});

module.exports = mongoose.model('order', OrderSchema);
38 changes: 38 additions & 0 deletions Hacknation /Cyber Quads/College-Canteen-Server/models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { default: mongoose } = require("mongoose");
const { Schema } = mongoose;
// const req = require("mongoose");

const UserSchema = new Schema({
googleID:{
type: String,
required: false,
unique:true,
},
name:{
type: String,
required: true
},
email:{
type: String,
required: true,
unique:true
},
phone:{
type: Number,
required: false,
unique: true
},
passwordHash:{
type: String,
required: false
},
timestamp:{
type: String,
required: true,
default: Date
}
});

const User = mongoose.model('user', UserSchema);
// User.createIndexes();
module.exports = User;
Loading