commit
2606644244
27
app.js
27
app.js
|
@ -1,4 +1,5 @@
|
|||
const express = require("express");
|
||||
const app = express();
|
||||
const mongoose = require("mongoose");
|
||||
const bodyparser = require("body-parser");
|
||||
const authRoute = require("./routes/auth");
|
||||
|
@ -11,7 +12,6 @@ const adminRoute = require("./routes/admin");
|
|||
const blogRouter = require("./routes/blog");
|
||||
const port = process.env.PORT || 5000;
|
||||
const cors = require("cors");
|
||||
const app = express();
|
||||
|
||||
//const passport = require('passport');
|
||||
//const cookieSession = require('cookie-session') ;
|
||||
|
@ -75,21 +75,18 @@ app.use(bodyparser.json());
|
|||
// req.logout() ;
|
||||
// res.redirect('/') ;
|
||||
// })
|
||||
mongoose
|
||||
.connect(MONGO_URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useFindAndModify: false,
|
||||
})
|
||||
.then((result) => {
|
||||
console.log("connected");
|
||||
app.listen(port, () => {
|
||||
console.log("server is running on port", port);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
|
||||
mongoose.connect(MONGO_URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useFindAndModify: false,
|
||||
});
|
||||
let conn = mongoose.connection.on("connected", (res) => {
|
||||
console.log("Connected to MongoDB");
|
||||
app.listen(port, () => {
|
||||
console.log("Server Listening on Port", port);
|
||||
});
|
||||
});
|
||||
app.use(authRoute);
|
||||
|
||||
app.use(profileRoute);
|
||||
|
|
|
@ -8,6 +8,10 @@ const messagebird = require("messagebird")("llVKD53ve6QRpbCKOHzWBADaS", null, [
|
|||
]);
|
||||
const nodemailer = require("nodemailer");
|
||||
const smtpTransport = require("nodemailer-smtp-transport");
|
||||
// const { OAuth2Client } = require("google-auth-library");
|
||||
// const client = new OAuth2Client(
|
||||
// "7810129519-dr5l4l1i7a7bh07sbvl49gd80coenphj.apps.googleusercontent.com"
|
||||
// );
|
||||
|
||||
// -------------------------------------------- mail transporter -----------------------------------------
|
||||
|
||||
|
@ -148,6 +152,24 @@ module.exports.postSignin = async (req, res, next) => {
|
|||
console.log(err);
|
||||
}
|
||||
};
|
||||
// Gmail Login Starts.
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
//1026548376782-5p5tjck8ffhan9l1ajhv6orr87dfkrrf.apps.googleusercontent.com
|
||||
|
||||
// module.exports.googleSignIn = async (req, res, next) => {
|
||||
// const { tokenId } = req.params;
|
||||
// console.log("TokenId from frontend", tokenId);
|
||||
// client
|
||||
// .verifyIdToken({
|
||||
// idToken: tokenId,
|
||||
// audience:
|
||||
// "7810129519-dr5l4l1i7a7bh07sbvl49gd80coenphj.apps.googleusercontent.com",
|
||||
// })
|
||||
// .then((response) => {
|
||||
// console.log(response.payload);
|
||||
// });
|
||||
// };
|
||||
|
||||
// Phone verification Starts.
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -18,9 +18,26 @@ module.exports.getAllBlogs = async (req, res, next) => {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports.addBlog = async (req, res, next) => {
|
||||
const { _id, title, body, image, author } = req.body; //_id is of user from frontend who is adding the blog.
|
||||
module.exports.getSingleBlog = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
let blog = await Blog.findById({ _id: id });
|
||||
if (blog) {
|
||||
res.json({ blog });
|
||||
} else {
|
||||
res.json({ error: "Blog Not Found" });
|
||||
}
|
||||
} catch {
|
||||
(err) => {
|
||||
console.log("Error", err);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.addBlog = async (req, res, next) => {
|
||||
const { _id, title, body, author } = req.body; //_id is of user from frontend who is adding the blog.
|
||||
try {
|
||||
console.log("Image File", req.file);
|
||||
let user = await User.findById({ _id });
|
||||
if (!title) {
|
||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
||||
|
@ -34,8 +51,8 @@ module.exports.addBlog = async (req, res, next) => {
|
|||
let blog = new Blog({
|
||||
title,
|
||||
body,
|
||||
image,
|
||||
date: new Date(),
|
||||
image: req.file.location,
|
||||
date: new Date().toISOString(),
|
||||
author,
|
||||
});
|
||||
await blog.save();
|
||||
|
|
|
@ -10,7 +10,7 @@ const blogSchema = new mongoose.Schema({
|
|||
type: Date,
|
||||
},
|
||||
image: {
|
||||
type: String,
|
||||
type: Object,
|
||||
default: "",
|
||||
},
|
||||
body: {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,11 +19,16 @@
|
|||
"crypto": "^1.0.1",
|
||||
"dotenv": "^9.0.1",
|
||||
"express": "^4.17.1",
|
||||
"google-auth-library": "^7.0.4",
|
||||
"grandjs": "^2.2.30",
|
||||
"gridfs-stream": "^1.1.1",
|
||||
"handlebars": "^4.7.7",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"messagebird": "^3.6.1",
|
||||
"mongoose": "^5.12.2",
|
||||
"multer": "^1.4.2",
|
||||
"multer-gridfs-storage": "^4.2.0",
|
||||
"multer-s3": "^2.9.0",
|
||||
"nodemailer": "^6.6.0",
|
||||
"nodemailer-smtp-transport": "^2.7.4",
|
||||
"passport": "^0.4.1",
|
||||
|
|
|
@ -17,6 +17,8 @@ router.post("/forgotpassword", authController.forgotpassword);
|
|||
|
||||
router.post("/resetpassword/:_id/:token", authController.resetpassword);
|
||||
|
||||
// router.post("/googleSignIn/:tokenId", authController.googleSignIn);
|
||||
|
||||
// router.post("/verifyemail", authController.verfiyemail);
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
@ -2,11 +2,39 @@ const express = require("express");
|
|||
const router = express.Router();
|
||||
const BlogController = require("../controllers/blog");
|
||||
const isAuth = require("../middleware/requirelogin");
|
||||
const multer = require("multer");
|
||||
const multerS3 = require("multer-s3");
|
||||
const aws = require("aws-sdk");
|
||||
|
||||
router.post("/addBlog", BlogController.addBlog);
|
||||
aws.config.update({
|
||||
secretAccessKey: `${process.env.AWS_SEC}`,
|
||||
accessKeyId: `${process.env.AWS_KEY}`,
|
||||
region: "ap-south-1",
|
||||
});
|
||||
|
||||
const s3 = new aws.S3();
|
||||
|
||||
const upload = multer({
|
||||
storage: multerS3({
|
||||
s3: s3,
|
||||
acl: "public-read",
|
||||
bucket: "cantilever-blog-images",
|
||||
metadata: function (req, file, cb) {
|
||||
cb(null, { fieldName: file.originalname });
|
||||
},
|
||||
|
||||
key: function (req, file, cb) {
|
||||
cb(null, file.originalname);
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
router.post("/addBlog", upload.single("blog_image"), BlogController.addBlog);
|
||||
|
||||
router.get("/getAllBlogs", BlogController.getAllBlogs);
|
||||
|
||||
router.get("/blog/:id", BlogController.getSingleBlog);
|
||||
|
||||
router.post("/deleteBlog/", BlogController.deleteBlog);
|
||||
|
||||
router.post("/editBlog/", BlogController.editBlog);
|
||||
|
|
Loading…
Reference in New Issue