백앤드의 rds 와 연결한 좌바 스프링부트는 앤드포인트 /api/url 에 대한 응답을 수신하면 requet를 출력 할 수 있도록 구성한다.
main class (클라이언트 접속 시에 진입점을 담당하는 어플레케이션의 시작을 담당한다) 와 동일한 동일한 디렉토리에ApiController.java 를 작성한다. 동일 디렉토리에 있으면 jar 파일로 빌드되면서 자동으로 스캔이 된다.
package cohttp://m.example.demo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class ApiController {
@RequestMapping(value = "/api/super-shy", method = RequestMethod.PATCH)
public ResponseEntity<MyResponse> handleSuperShyPatchRequest() {
// PATCH 요청을 처리하는 로직
MyResponse response = new MyResponse("Super Shy PATCH 요청이 처리되었습니다.");
return new ResponseEntity<>(response, HttpStatus.OK);
}
@RequestMapping(value = "/api/super-shy", method = RequestMethod.GET)
public ResponseEntity<MyResponse> handleSuperShyGetRequest() {
// GET 요청을 처리하는 로직
MyResponse response = new MyResponse("Super Shy GET 요청이 처리되었습니다.");
return new ResponseEntity<>(response, HttpStatus.OK);
}
static class MyResponse {
private String message;
public MyResponse(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
}
package cohttp://m.example.demo; : 이것은 반드시 들어가야 한다. 빼 버리면 빌드 할 때 자동 스캔이 안된다.
메인클라스와 동일한 패키지에 속해 있다는 것은 선언.
build.gradle 에는 의존성 추가
implementation 'org.springframework.boot:spring-boot-starter-web'
역방향 프록시 서버를 이미지빌드를 위한 도커 이미지 작성
# 기본 이미지로부터 시작
FROM nginx:latest
# 작업 디렉토리 설정
WORKDIR /usr/share/nginx/html
# 로컬 파일을 컨테이너 내부로 복사
COPY assets /usr/share/nginx/html/assets
COPY config.js /usr/share/nginx/html/config.js
COPY contact.html /usr/share/nginx/html/contact.html
COPY css /usr/share/nginx/html/css
COPY index.html /usr/share/nginx/html/index.html
COPY js /usr/share/nginx/html/js
COPY projects.html /usr/share/nginx/html/projects.html
COPY resume.html /usr/share/nginx/html/resume.html
# Nginx 설정 파일을 컨테이너 내부로 복사
COPY nginx.conf /etc/nginx/nginx.conf
# 컨테이너 실행 시 Nginx 자동 시작
CMD ["nginx", "-g", "daemon off;"]
nginx.conf 은 원래 /etc/nginx/conf.d/defalut.conf 이다 이름을 수정해줬다.
web-was 구축해보기 (nginx-proxy) -(3) (1) | 2024.04.07 |
---|---|
web-was 구축해보기 (nginx-proxy) -(1) (0) | 2024.04.06 |
maven 프로젝트를 젠킨슨에서 도커 이미지 빌드 (CI) -kaniko (0) | 2024.03.10 |
maven 프로젝트 빌드 - springboot(rds연동) (0) | 2024.03.10 |
eks 웹어플리케이션 배포 영상 (CI/CD) (0) | 2024.03.08 |