Skip to content

Commit

Permalink
Merge pull request #79 from Murakano/dev
Browse files Browse the repository at this point in the history
♻️ client ip 가져오는 방법 변경
  • Loading branch information
jjikky authored Jul 20, 2024
2 parents 2f6d156 + f5bb1e3 commit 590ccc6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/common/modules/express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ module.exports = expressLoader = (app) => {
// ip 블랙리스트
app.use(async (req, res, next) => {
// TODO : PROD 체크 후 삭제
const clientIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('clientIp: ' + clientIp);
const clientIp = req.headers['x-forwarded-for']
? req.headers['x-forwarded-for'].split(',')[0].trim()
: req.connection.remoteAddress;
try {
const blockTime = await redisClient.get(clientIp);
if (blockTime && blockTime > Date.now()) {
Expand Down
4 changes: 3 additions & 1 deletion src/common/utils/rateLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ exports.commonLimiter = rateLimit({
windowMs: 60 * 1000, // 1분 간격
max: 200, // windowMs동안 최대 호출 횟수
handler: async (req, res) => {
const clientIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
const clientIp = req.headers['x-forwarded-for']
? req.headers['x-forwarded-for'].split(',')[0].trim()
: req.connection.remoteAddress;
try {
await redisClient.set(clientIp, Date.now() + BLOCK_DURATION);
// 1시간 후 제거
Expand Down

0 comments on commit 590ccc6

Please sign in to comment.