Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ client ip 가져오는 방법 변경 #79

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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