Skip to content

Commit

Permalink
feat: get places review & rating 정렬 오류 수정
Browse files Browse the repository at this point in the history
fix: get place docs 수정
  • Loading branch information
1000chw committed Apr 9, 2024
1 parent 6d07fff commit 7515b46
Show file tree
Hide file tree
Showing 5 changed files with 875 additions and 705 deletions.
82 changes: 45 additions & 37 deletions config/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,68 @@ import { response } from "./response";
require("dotenv").config();

const format = () => {
const result = process.env.NODE_ENV === "production" ? "combined" : "dev";
return result;
const result = process.env.NODE_ENV === "production" ? "combined" : "dev";
return result;
};

// 로그 작성을 위한 Output stream옵션.
const stream = {
write: (message) => {
logger.info(message.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ""));
},
write: (message) => {
logger.info(
message.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
"",
),
);
},
};

const skip = (_, res) => {
if (process.env.NODE_ENV === "production") {
return res.ststusCode < 400;
}
return false;
if (process.env.NODE_ENV === "production") {
return res.ststusCode < 400;
}
return false;
};

const multerS3Uploader = multerS3({
s3,
bucket: "bookjam-dev-s3",
acl: "public-read",
contentType: multerS3.AUTO_CONTENT_TYPE,
key: (req, file, cb) => cb(null, `${Date.now()}_${file.originalname}`),
s3,
bucket: "bookjam-dev-s3",
acl: "public-read",
contentType: multerS3.AUTO_CONTENT_TYPE,
key: (req, file, cb) => cb(null, `${Date.now()}_${file.originalname}`),
});

const middlewares = {
s3Upload: multer({
dest: "uploads/images/",
limits: {
fieldSize: 5 * 1024 * 1024,
},
storage: multerS3Uploader,
}),
s3Upload: multer({
dest: "uploads/images/",
limits: {
fieldSize: 5 * 1024 * 1024,
},
storage: multerS3Uploader,
}),

logger: morgan(format(), { stream, skip }),
logger: morgan(format(), { stream, skip }),

authCheck: async (req, res, next) => {
const token = jwt.extractTokenFromHeader(req);
authCheck: async (req, res, next) => {
const token = jwt.extractTokenFromHeader(req);

if (!token) {
return res.status(401).json(baseResponse.JWT_TOKEN_EMPTY);
}
if (!token) {
return res.status(401).json(baseResponse.JWT_TOKEN_EMPTY);
}

try {
const payload = await jwt.verifyTokenAsync(token);
req.user = payload;
next();
} catch (error) {
logger.error(error.message);
if (error.name === "TokenExpiredError") return res.status(401).json(baseResponse.ACCESS_TOKEN_EXPIRED);
return res.status(401).json(response(baseResponse.JWT_VERIFICATION_FAILED));
}
},
try {
const payload = await jwt.verifyTokenAsync(token);
req.user = payload;
next();
} catch (error) {
logger.error(error.message);
if (error.name === "TokenExpiredError")
return res.status(401).json(baseResponse.ACCESS_TOKEN_EXPIRED);
return res
.status(401)
.json(response(baseResponse.JWT_VERIFICATION_FAILED));
}
},
};

export default middlewares;
Loading

0 comments on commit 7515b46

Please sign in to comment.