first commit
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
.env
|
7
Utils/cloudinary.js
Normal file
@ -0,0 +1,7 @@
|
||||
import cloudinary from "cloudinary"
|
||||
cloudinary.v2.config({
|
||||
cloud_name: process.env.CLOUDINARY_NAME,
|
||||
api_key: process.env.CLOUDINARY_API_KEY,
|
||||
api_secret: process.env.CLOUDINARY_API_SECRET,
|
||||
});
|
||||
export default cloudinary;
|
23
Utils/jwtToken.js
Normal file
@ -0,0 +1,23 @@
|
||||
// Create Token and saving in cookie
|
||||
|
||||
const sendToken = (user, statusCode, res) => {
|
||||
const token = user.getJWTToken();
|
||||
// consolelog(token)
|
||||
//options for cookie
|
||||
const options = {
|
||||
expires: new Date(
|
||||
Date.now() + 24 * 60 * 60 * 1000
|
||||
),
|
||||
httpOnly: true,
|
||||
};
|
||||
|
||||
res.status(statusCode).cookie("token", token, options).json({
|
||||
// res.status(statusCode).json({
|
||||
|
||||
success: true,
|
||||
user,
|
||||
token,
|
||||
});
|
||||
};
|
||||
|
||||
export default sendToken;
|
33
app.js
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
import dotenv from "dotenv";
|
||||
import express from 'express';
|
||||
const app = express();
|
||||
import bodyParser from "body-parser";
|
||||
import fileUpload from "express-fileupload"// important pkg for file upload
|
||||
import cors from 'cors'
|
||||
import cookieParser from "cookie-parser"
|
||||
|
||||
// app.use(express.json({ limit: "50mb" }));
|
||||
// app.use(express.urlencoded({ extended: true, limit: "50mb" }));
|
||||
app.use(cookieParser());
|
||||
|
||||
|
||||
//handdle cores
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
//express file upload
|
||||
app.use(fileUpload({
|
||||
useTempFiles: true
|
||||
}));
|
||||
|
||||
import user from "./routes/userRoute.js"
|
||||
app.use("/api", user);
|
||||
import category from "./routes/categoryRoute.js"
|
||||
app.use("/api", category);
|
||||
//directory
|
||||
import directory from "./routes/directoryRoute.js"
|
||||
app.use("/api", directory);
|
||||
|
||||
export default app;
|
159
controllers/categoryController.js
Normal file
@ -0,0 +1,159 @@
|
||||
import Category from "../models/categoryModel.js"
|
||||
import cloudinary from "cloudinary";
|
||||
// import cloudinary from "../Utils/cloudinary.js"
|
||||
//import { v2 as cloudinary } from 'cloudinary'
|
||||
|
||||
export const createCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const files = req.files.image;
|
||||
|
||||
// console.log(files)
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
const { name } = req.body;
|
||||
|
||||
const data = await Category.create({
|
||||
name,
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
},
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Category Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Product
|
||||
export const getAllCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const category = await Category.find();
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Product
|
||||
export const getOneCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const category = await Category.findById(req.params.id);
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
category,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 8.update Category
|
||||
export const updateCategory = async (req, res) => {
|
||||
try {
|
||||
const newCategoryData = {
|
||||
name: req.body.name,
|
||||
// email: req.body.email,
|
||||
};
|
||||
const files = req.files.image;
|
||||
|
||||
if (req.files.image !== "") {
|
||||
const categ = await Category.findById(req.params.id);
|
||||
|
||||
const imageId = categ.image.public_id;
|
||||
// console.log(imageId)
|
||||
//delete image from claudinary
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
// await cloudinary.uploader.destroy(imageId, function (result) { console.log(result) });
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
// console.log(myCloud)
|
||||
newCategoryData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
};
|
||||
}
|
||||
// console.log(newCategoryData)
|
||||
//req.user.id,
|
||||
const ModifyCategory = await Category.findByIdAndUpdate(req.params.id, newCategoryData,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyCategory
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate !!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one category
|
||||
export const deleteOneCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
const categ = await Category.findById(req.params.id);
|
||||
// console.log(categ)
|
||||
const imageId = categ.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
|
||||
//-------------------------//
|
||||
const category = await Category.findByIdAndDelete(req.params.id)
|
||||
if (!category) {
|
||||
return res.status(400).json({ message: 'category Not Found' });
|
||||
}
|
||||
await category.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "category Deleted Successfully!!",
|
||||
// category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
116
controllers/directoryController.js
Normal file
@ -0,0 +1,116 @@
|
||||
import directoryModel from "../models/directoryModel.js";
|
||||
export const createDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
console.log("hii")
|
||||
const { name,
|
||||
phone,
|
||||
email,
|
||||
Bname,
|
||||
Sname,
|
||||
country,
|
||||
city,
|
||||
description,
|
||||
category,
|
||||
status,
|
||||
Glocation,
|
||||
LinkedinUrl,
|
||||
FacebookUrl,
|
||||
InstagramUrl,
|
||||
} = req.body.state;
|
||||
// console.log(name)
|
||||
const data = await directoryModel.create({
|
||||
|
||||
name,
|
||||
phone,
|
||||
email,
|
||||
Building_Name: Bname,
|
||||
Street_Name: Sname,
|
||||
country,
|
||||
city,
|
||||
description,
|
||||
category,
|
||||
status,
|
||||
Glocation,
|
||||
LinkedinUrl,
|
||||
FacebookUrl,
|
||||
InstagramUrl,
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Directory Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(err)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//get All Product
|
||||
export const getAllDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const directory = await directoryModel.find();
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
directory,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Product
|
||||
export const getOneDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const directory = await directoryModel.findById(req.params.id);
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
directory,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//delete one category
|
||||
export const deleteOneDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const directory = await directoryModel.findByIdAndDelete(req.params.id)
|
||||
if (!directory) {
|
||||
return res.status(400).json({ message: 'Directory Not Found' });
|
||||
}
|
||||
await directory.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Directory Deleted Successfully!!",
|
||||
// category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
129
controllers/userController.js
Normal file
@ -0,0 +1,129 @@
|
||||
|
||||
import User from "../models/userModel.js"
|
||||
import sendToken from "../Utils/jwtToken.js"
|
||||
// 1.Register a User
|
||||
export const registerUser = async (req, res) => {
|
||||
try {
|
||||
const { name, email, password, confirmPassword } = req.body;
|
||||
// console.log(name)
|
||||
if (password !== confirmPassword) {
|
||||
res.status(401).json({ msg: "Password not Match!!" })
|
||||
}
|
||||
const user = await User.create({
|
||||
name,
|
||||
email,
|
||||
password
|
||||
});
|
||||
// const token = user.getJWTToken();
|
||||
// console.log(token)
|
||||
// res.status(201).json({
|
||||
// success: true,
|
||||
// token,
|
||||
// })
|
||||
sendToken(user, 201, res);
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to register !!"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 2.Login User
|
||||
export const loginUser = async (req, res) => {
|
||||
try {
|
||||
const { email, password } = req.body;
|
||||
|
||||
// checking if user has given password and email both
|
||||
|
||||
if (!email || !password) {
|
||||
res.status(400).json({ msg: "Please Enter Email & Password" })
|
||||
}
|
||||
|
||||
const user = await User.findOne({ email }).select("+password");
|
||||
|
||||
if (!user) {
|
||||
res.status(401).json({ msg: "Invalid email or password" })
|
||||
}
|
||||
|
||||
const isPasswordMatched = await user.comparePassword(password);
|
||||
|
||||
if (!isPasswordMatched) {
|
||||
res.status(401).json({ msg: "Invalid email or password" })
|
||||
}
|
||||
// const token = user.getJWTToken();
|
||||
// res.status(201).json({
|
||||
// success: true,
|
||||
// token,
|
||||
// })
|
||||
sendToken(user, 200, res);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Login !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// 3.Logout User
|
||||
export const logout = async (req, res) => {
|
||||
try {
|
||||
res.cookie("token", null, {
|
||||
expires: new Date(Date.now()),
|
||||
httpOnly: true,
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Logged Out",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to logOut !!"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
// 4.update User password
|
||||
export const updatePassword = async (req, res) => {
|
||||
try {
|
||||
// console.log("fhrbhebhgbfr")
|
||||
// console.log(req.user._id)
|
||||
if (!req.user) {
|
||||
return res.status(400).json({ message: 'User Not Found' });
|
||||
}
|
||||
const user = await User.findById(req.user._id).select("+password");
|
||||
|
||||
const isPasswordMatched = await user.comparePassword(req.body.oldPassword);
|
||||
|
||||
if (!isPasswordMatched) {
|
||||
res.status(400).json({ msg: "Old password is incorrect" })
|
||||
|
||||
}
|
||||
|
||||
if (req.body.newPassword !== req.body.confirmPassword) {
|
||||
res.status(400).json({ msg: "password does not match" })
|
||||
|
||||
}
|
||||
|
||||
user.password = req.body.newPassword;
|
||||
|
||||
await user.save();
|
||||
|
||||
sendToken(user, 200, res);
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Password Change !!"
|
||||
});
|
||||
}
|
||||
}
|
14
database/db.js
Normal file
@ -0,0 +1,14 @@
|
||||
import mongoose from "mongoose";
|
||||
//require("dotenv").config();
|
||||
|
||||
const connectDatabase = () => {
|
||||
mongoose
|
||||
.connect(process.env.DB_URL, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
|
||||
}).then((data) => {
|
||||
console.log(`Mongodb connected with server: ${data.connection.host}`);
|
||||
})
|
||||
};
|
||||
export default connectDatabase;
|
35
middlewares/auth.js
Normal file
@ -0,0 +1,35 @@
|
||||
import User from "../models/userModel.js";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
export const isAuthenticated = async (req, res, next) => {
|
||||
try {
|
||||
// const { token } = req.cookies;
|
||||
const getToken = req.headers;
|
||||
// // console.log(getToken.authorization)
|
||||
|
||||
// //remove Bearer from token
|
||||
const token = getToken.authorization.slice(7);
|
||||
// // console.log(token)
|
||||
|
||||
if (!token) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Login to Access this resource",
|
||||
});
|
||||
}
|
||||
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
||||
// console.log(decoded)
|
||||
const user = await User.findById(decoded.id);
|
||||
// console.log(user)
|
||||
req.user = user;
|
||||
// console.log(req.user)
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
};
|
27
models/categoryModel.js
Normal file
@ -0,0 +1,27 @@
|
||||
import mongoose from "mongoose"
|
||||
const categorySchema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
addedOn: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const categoryUpload = mongoose.model("category", categorySchema);
|
||||
export default categoryUpload;
|
64
models/directoryModel.js
Normal file
@ -0,0 +1,64 @@
|
||||
import mongoose from "mongoose"
|
||||
const directorySchema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
phone: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true
|
||||
},
|
||||
Building_Name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
Street_Name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
country: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
city: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
category: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
Glocation: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
LinkedinUrl: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
FacebookUrl: {
|
||||
type: String,
|
||||
},
|
||||
InstagramUrl: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const directoryModel = mongoose.model("directory", directorySchema);
|
||||
export default directoryModel;
|
52
models/userModel.js
Normal file
@ -0,0 +1,52 @@
|
||||
import mongoose from "mongoose"
|
||||
import validator from "validator"
|
||||
import bcrypt from "bcryptjs"
|
||||
import jwt from "jsonwebtoken"
|
||||
import crypto from "crypto"
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: [true, "Please Enter Your Name"],
|
||||
maxLength: [30, "Name cannot exceed 30 characters"],
|
||||
minLength: [3, "Name should have more than 4 characters"],
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: [true, "Please Enter Your Email"],
|
||||
unique: true,
|
||||
validate: [validator.isEmail, "Please Enter a valid Email"],
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: [true, "Please Enter Your Password"],
|
||||
minLength: [4, "Password should be greater than 8 characters"],
|
||||
select: false,//find not got passpord
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
|
||||
userSchema.pre("save", async function (next) {
|
||||
if (!this.isModified("password")) {
|
||||
next();
|
||||
}
|
||||
|
||||
this.password = await bcrypt.hash(this.password, 10);
|
||||
});
|
||||
|
||||
// JWT TOKEN
|
||||
userSchema.methods.getJWTToken = function () {
|
||||
return jwt.sign({ id: this._id }, process.env.JWT_SECRET, {//make token
|
||||
expiresIn: "1d",
|
||||
});
|
||||
};
|
||||
//process.env.JWT_SECRET
|
||||
|
||||
// Compare Password
|
||||
userSchema.methods.comparePassword = async function (password) {
|
||||
return await bcrypt.compare(password, this.password);
|
||||
};
|
||||
|
||||
const UserModel = mongoose.model("User", userSchema);
|
||||
export default UserModel;
|
3291
package-lock.json
generated
Normal file
27
package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "dashboard-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "nodemon server.js"
|
||||
},
|
||||
"author": "pawan",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcryptjs": "^2.4.3",
|
||||
"body-parser": "^1.20.0",
|
||||
"cloudinary": "^1.30.0",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.18.1",
|
||||
"express-fileupload": "^1.4.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mongoose": "^6.3.5",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"validator": "^13.7.0"
|
||||
}
|
||||
}
|
16
routes/categoryRoute.js
Normal file
@ -0,0 +1,16 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createCategory,
|
||||
getAllCategory,
|
||||
updateCategory,
|
||||
deleteOneCategory,
|
||||
getOneCategory
|
||||
} from "../controllers/categoryController.js"
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/category/create/").post(createCategory)
|
||||
router.route("/category/getAll/").get(getAllCategory)
|
||||
router.route("/category/getOne/:id").get(getOneCategory)
|
||||
router.route("/category/update/:id").put(updateCategory);
|
||||
router.route("/category/delete/:id").delete(deleteOneCategory);
|
||||
export default router;
|
16
routes/directoryRoute.js
Normal file
@ -0,0 +1,16 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createDirectory,
|
||||
getAllDirectory,
|
||||
// updateCategory,
|
||||
deleteOneDirectory,
|
||||
getOneDirectory
|
||||
} from "../controllers/directoryController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticated } from "../middlewares/auth.js"
|
||||
router.route("/directory/create/").post(createDirectory)
|
||||
router.route("/directory/getAll/").get(getAllDirectory)
|
||||
router.route("/directory/getOne/:id").get(getOneDirectory)
|
||||
// router.route("/category/update/:id").put(updateCategory);
|
||||
router.route("/directory/delete/:id").delete(deleteOneDirectory);
|
||||
export default router;
|
31
routes/userRoute.js
Normal file
@ -0,0 +1,31 @@
|
||||
import express from "express";
|
||||
// import isAuthenticated from "../Utils/aurhe";
|
||||
import {
|
||||
registerUser,
|
||||
loginUser,
|
||||
logout,
|
||||
updatePassword
|
||||
} from "../controllers/userController.js"
|
||||
// import {isAuthenticatedUser} from "../Middleware/Auth.js";
|
||||
import { isAuthenticated } from "../middlewares/auth.js"
|
||||
import multer from 'multer'
|
||||
|
||||
const uploaderImage = multer({
|
||||
storage: multer.diskStorage({}),
|
||||
fileFilter: (req, file, cb) => {
|
||||
let ext = path.extname(file.originalname);
|
||||
if (ext !== ".jpg" && ext !== ".jpeg" && ext !== ".png") {
|
||||
cb(new Error("File type not supported!"), false)
|
||||
return
|
||||
}
|
||||
cb(null, true);
|
||||
}
|
||||
});
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/user/register/").post(uploaderImage.single("image"), registerUser)
|
||||
router.route("/user/login/").post(loginUser)
|
||||
router.route("/user/logout").get(logout);
|
||||
router.route("/user/update/password").put(isAuthenticated, updatePassword);
|
||||
|
||||
export default router;
|
46
server.js
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
import app from "./app.js"
|
||||
import connectDatabase from "./database/db.js";
|
||||
import cloudinary from "cloudinary"
|
||||
// const PORT = 5000;
|
||||
// Connecting to database
|
||||
connectDatabase();
|
||||
|
||||
// console.log(process.env.CLOUDINARY_API_KEY)
|
||||
//cloudenary uses
|
||||
cloudinary.config({
|
||||
cloud_name: process.env.CLOUDINARY_NAME,
|
||||
api_key: process.env.CLOUDINARY_API_KEY,
|
||||
api_secret: process.env.CLOUDINARY_API_SECRET,
|
||||
});
|
||||
//<---------deployement------------->
|
||||
// const data_dir = path.resolve();
|
||||
|
||||
// if (process.env.NODE_ENV === "production") {
|
||||
// app.use(express.static(path.join(data_dir, "/frontend/build")));
|
||||
|
||||
// app.get("*", (req, res) =>
|
||||
// res.sendFile(path.join(data_dir, "frontend", "build", "index.html"))
|
||||
// );
|
||||
// } else {
|
||||
app.get("/", (req, res) => {
|
||||
res.send("API is running..");
|
||||
});
|
||||
// }
|
||||
//<---------deployement------------->
|
||||
const server = app.listen(process.env.PORT, () => {
|
||||
console.log(`Server is working on http://localhost:${process.env.PORT}`)
|
||||
})
|
||||
|
||||
|
||||
// Unhandled Promise Rejection
|
||||
process.on("unhandledRejection", (err) => {
|
||||
console.log(`Error: ${err.message}`);
|
||||
console.log(`Shutting down the server due to Unhandled Promise Rejection`);
|
||||
|
||||
server.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
BIN
tmp/tmp-1-1654002583895
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654002645769
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654002809064
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654057698129
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654084776929
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654084872872
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654085303382
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654087414761
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654087811966
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654088119927
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654088213266
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654088320866
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654088445927
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654088622981
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654088758878
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654090512031
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654091614855
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654094231227
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654094484557
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654094792595
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654095352937
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654095430166
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654146630538
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149236779
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149321275
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149382816
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149407425
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149463075
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149496310
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149551840
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149584661
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149618714
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149654518
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149695616
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654149937933
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654152658323
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654152868646
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654154957119
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654155027617
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654155072136
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654155219237
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654155350634
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-1-1654156012950
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1654158272491
Normal file
After Width: | Height: | Size: 620 KiB |
BIN
tmp/tmp-1-1654162401505
Normal file
After Width: | Height: | Size: 620 KiB |
BIN
tmp/tmp-1-1654169492070
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-10-1654163490528
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-11-1654163672640
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-12-1654163809625
Normal file
After Width: | Height: | Size: 620 KiB |
BIN
tmp/tmp-13-1654164010539
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-14-1654166900581
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-15-1654167280576
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
tmp/tmp-2-1654002590797
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-2-1654084812611
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-2-1654087877521
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-2-1654094324700
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-2-1654094857531
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-2-1654149433577
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-2-1654149522400
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-2-1654150221782
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
tmp/tmp-2-1654155436262
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-2-1654157404214
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-2-1654158372211
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
tmp/tmp-2-1654162432202
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-2-1654169564302
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-3-1654157507741
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-3-1654162602691
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-3-1654169649696
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-4-1654162722085
Normal file
After Width: | Height: | Size: 620 KiB |
BIN
tmp/tmp-4-1654169723645
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-5-1654162743169
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-6-1654162818956
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-7-1654162852612
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
tmp/tmp-8-1654163116974
Normal file
After Width: | Height: | Size: 620 KiB |
BIN
tmp/tmp-9-1654163345184
Normal file
After Width: | Height: | Size: 1.7 MiB |