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

Develop back README.md #236

Merged
merged 23 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
55ff7c3
feature: #230 - 로깅 강화
mclub4 May 21, 2024
48b7152
chore : encrypt tool 추가
mclub4 May 21, 2024
e229a2c
chore : README 추가
mclub4 May 21, 2024
4c36eae
chore : env example 작성
mclub4 May 21, 2024
bc2a90e
chore : 공지사항 크롤링 시간 변경
mclub4 May 21, 2024
f62eadf
chore : README 일부 작성
mclub4 May 21, 2024
4f27712
Update README.md
mclub4 May 22, 2024
2cf4567
fix: 크롤링 당일 것만 되도록 수정
mclub4 May 22, 2024
82e9257
Merge pull request #231 from kookmin-sw/feature/be/#230-Loggig
BlueBerrySoda May 22, 2024
2d64318
Update GlobalLoggingFilter.java
mclub4 May 22, 2024
f43e14d
Update GlobalLoggingFilter.java
mclub4 May 22, 2024
3f904b7
feat: #232-cloud front 캐싱 주소저장 변경
BlueBerrySoda May 22, 2024
d0b5253
Update deploy.yml
BlueBerrySoda May 22, 2024
b0910a4
Update .env.example
BlueBerrySoda May 22, 2024
78861be
Merge pull request #233 from kookmin-sw/feature/be/#232-cloud-front
BlueBerrySoda May 22, 2024
fe6151e
fix: 로깅 수정
mclub4 May 22, 2024
b947387
fix: gradlew 개행 문제 해결
mclub4 May 22, 2024
cd6447e
Merge pull request #234 from kookmin-sw/feature/be/#230-Loggig
mclub4 May 22, 2024
5b81e30
fix: GET일때 Body 로깅 제외
mclub4 May 22, 2024
8f31b10
fix: docker nextwork 재구성
mclub4 May 22, 2024
e18f418
Merge pull request #235 from kookmin-sw/feature/be/#230-Loggig
mclub4 May 22, 2024
f8d3faa
fix: POST 요청시 Body가 전달안되던 오류
mclub4 May 22, 2024
077ed13
Update README.md
BlueBerrySoda May 22, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
echo REDIS_PORT=${{ secrets.REDIS_PORT }} >> .env
echo S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} >> .env
echo S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }} >> .env
echo CLOUD_FRONT_URL=${{ secrets.CLOUD_FRONT_URL }} >> .env
echo SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }} >> .env
echo SERVER_NAME=${{ secrets.SERVER_NAME }} >> .env
echo SERVER_URL=${{ secrets.SERVER_URL }} >> .env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public GatewayFilter apply(Config config) {
GatewayFilter filter = (exchange, chain) -> {
String requiredRole = config.getRequiredRole();
ServerHttpRequest request = exchange.getRequest();
log.info("요청한 uri : " + request.getURI());

if (!request.getHeaders().containsKey(HttpHeaders.AUTHORIZATION))
throw JwtTokenInvalidException.INSTANCE;

String token = request.getHeaders()
.getFirst(HttpHeaders.AUTHORIZATION).replace("Bearer ", "");

log.info("Authorization Token : {}", token);

if (!validateToken(token)) {
throw JwtTokenInvalidException.INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.gateway.backgateway.filter;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.nio.charset.StandardCharsets;

@Slf4j
@Configuration
public class GlobalLoggingFilter {

private final ObjectMapper objectMapper = new ObjectMapper();

@Bean
@Order(-1)
public GlobalFilter preLoggingFilter() {
return (exchange, chain) -> {
ServerHttpRequest request = exchange.getRequest();

log.info("Global Filter Start: request id -> {}", request.getId());
log.info("Request: {} {}", request.getMethod(), request.getURI());

if (request.getHeaders().containsKey("Authorization")) {
log.info("Authorization: {}", request.getHeaders().get("Authorization"));
}

if (request.getMethod().toString().equals("GET")) {
return chain.filter(exchange);
}

return DataBufferUtils.join(request.getBody())
.flatMap(dataBuffer -> {
byte[] bodyBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bodyBytes);
DataBufferUtils.release(dataBuffer);
String bodyString = new String(bodyBytes, StandardCharsets.UTF_8);

String jsonBody;
try {
Object json = objectMapper.readValue(bodyString, Object.class);
jsonBody = objectMapper.writeValueAsString(json);
} catch (Exception e) {
jsonBody = bodyString;
}

log.info("Request Body: {}", jsonBody);

ServerHttpRequest mutatedRequest = new ServerHttpRequestDecorator(request) {
@Override
public Flux<DataBuffer> getBody() {
DataBuffer buffer = exchange.getResponse().bufferFactory().wrap(bodyBytes);
return Flux.just(buffer);
}
};

return chain.filter(exchange.mutate().request(mutatedRequest).build());
});
};
}

@Bean
@Order(Ordered.LOWEST_PRECEDENCE)
public GlobalFilter postLoggingFilter() {
return (exchange, chain) -> chain.filter(exchange).then(Mono.fromRunnable(() -> {
log.info("Response: {}", exchange.getResponse().getStatusCode());
}));
}
}
8 changes: 8 additions & 0 deletions back-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ spring:
data: 0



jwt:
secret:
key: ${JWT_SECRET}


server:
port: 8081
chatbot-url: ${CHATBOT_URL}

logging:
level:
root: INFO
com:
gateway:
backgateway: DEBUG
38 changes: 37 additions & 1 deletion back/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
# JWT Secret Key
JWT_SECRET=
JWT_ACCESS_EXPIRATION_TIME=
JWT_REFRESH_EXPIRATION_TIME=

# HMAC
HMAC_SECRET=
HMAC_ALGORITHM=
HMAC_ALGORITHM=

#DeepL
DeepL_API_KEY=

#MYSQL
DB_ENDPOINT=
DB_PORT=
DB_NAME=
MYSQL_USERNAME=
MYSQL_PASSWORD=

#TEST
TEST_KEY=

#Azure
Azure_API_KEY=

##REDIS
REDIS_HOST=
REDIS_PORT=

## S3
S3_ACCESS_KEY=
S3_SECRET_KEY=
CLOUD_FRONT_URL=

## Ruby On Rails Production Key
SECRET_KEY_BASE=

## Nginx ENV
SERVER_NAME=

## CHAT BOT ENV
CHATBOT_URL=
Loading