Skip to content

Commit

Permalink
[fix] article intro, decode html author bio
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucky-victory committed Apr 8, 2022
1 parent b7de27a commit 6a0bf2f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions constants/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@



const isProd=process.env.NODE_ENV=='production';
const isDev=process.env.NODE_ENV=='development';
const IS_PROD=process.env.NODE_ENV==='production';
const IS_DEV=process.env.NODE_ENV !=='production';

module.exports={
isProd,
isDev
IS_PROD,
IS_DEV
}
3 changes: 2 additions & 1 deletion controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getPublishedArticles=asyncHandler(async(req,res)=>{
res.status(200).json({message:"No more Articles","articles":[]});
return
}
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=true ${!NullOrUndefined(category) ? ` AND category='${category}'`:''} ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.intro,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=true ${!NullOrUndefined(category) ? ` AND category='${category}'`:''} ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;

let articles=await Articles.query(articlesQuery);
// nest author info as author property
Expand All @@ -36,6 +36,7 @@ const getPublishedArticles=asyncHandler(async(req,res)=>{
articles=articles.map((article)=>{
article.title=decode(article.title);
article.content=decode(article.content);
article.author.bio=decode(article.author.bio);
article.tags=StringToArray(article.tags)
return article;
});
Expand Down
4 changes: 2 additions & 2 deletions helpers/auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cookie=require("cookie");
const { NullOrUndefined } = require("./utils");
const jwt=require('jsonwebtoken');
const { isProd } = require("../constants");
const { IS_PROD } = require("../constants");


const getJwtFromCookies=(req)=>{
Expand All @@ -11,7 +11,7 @@ const getJwtFromCookies=(req)=>{
return ({token})
}
const setJwtToCookies=(res,token='')=>{
res.cookie("blog_user_token",token,{httpOnly:isProd,secure:isProd});
res.cookie("blog_user_token",token,{httpOnly:IS_PROD,secure:IS_PROD});
}
const verifyToken=(token)=>{
return jwt.verify(token,process.env.JWT_SECRET || "12345")
Expand Down
6 changes: 3 additions & 3 deletions middlewares/csrf-protect.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const csurf=require("csurf");
const { isProd } = require("../constants");
const { IS_PROD } = require("../constants");

const csrfProtect=csurf({cookie:{
httpOnly:isProd,
secure:isProd
httpOnly:IS_PROD,
secure:IS_PROD
}});

module.exports={csrfProtect};
2 changes: 1 addition & 1 deletion request.rest
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Content-Type: application/json

}

###
###
PUT https://4901-luckyvictory-blogapi-pzfdy6iu340.ws-eu38.gitpod.io/profile/edit
Content-Type: application/json

Expand Down
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const createErrors=require('http-errors');
const fs=require('fs');
const path=require('path');
const morgan=require("morgan");
const { isDev } = require('./constants');
const { IS_DEV } = require('./constants');
const connectDB=require('./config/db');
connectDB();

Expand Down Expand Up @@ -63,7 +63,7 @@ return {
status,
code,
message,
"stack":isDev ? stack : null
"stack":IS_DEV ? stack : null
}
}

Expand Down

0 comments on commit 6a0bf2f

Please sign in to comment.