Skip to content

Commit 93c6918

Browse files
authored
fix: CORS 설정 추가 (#27)
* fix: 파일 이름, 파일 경로 파라미터 순서 수정 * config: cors 허용 url 설정 추가 * feat: cors 허용 url 설정 추가 * feat: 사진 조회 API 위치 반환 하도록 수정
1 parent 6cacd47 commit 93c6918

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

src/main/java/kr/kro/photoliner/domain/photo/dto/response/PhotosResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public record InnerPhotoResponse(
2323
Long id,
2424
String filePath,
2525
LocalDateTime capturedDt,
26+
double lat,
27+
double lng,
2628
Long userId
2729
) {
2830

@@ -31,6 +33,8 @@ public static InnerPhotoResponse from(Photo photo) {
3133
photo.getId(),
3234
photo.getFilePath(),
3335
photo.getCapturedDt(),
36+
photo.getLocation().getY(),
37+
photo.getLocation().getX(),
3438
photo.getUser().getId());
3539
}
3640
}

src/main/java/kr/kro/photoliner/domain/photo/service/PhotoUploadService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public PhotoUploadResponse uploadPhotos(Long userId, List<MultipartFile> files)
3333
String fileName = file.getOriginalFilename();
3434
User user = userRepository.findUserById(userId)
3535
.orElseThrow(RuntimeException::new);
36-
Photo photo = createPhoto(user, exifData, filePath, fileName);
36+
Photo photo = createPhoto(user, exifData, fileName, filePath);
3737
Photo savedPhoto = photoRepository.save(photo);
3838
return InnerUploadedPhotoInfo.from(savedPhoto);
3939
})

src/main/java/kr/kro/photoliner/global/config/WebMvcConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.RequiredArgsConstructor;
44
import org.springframework.beans.factory.annotation.Value;
55
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
67
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
78
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
89
import org.springframework.web.servlet.resource.PathResourceResolver;
@@ -11,9 +12,22 @@
1112
@RequiredArgsConstructor
1213
public class WebMvcConfig implements WebMvcConfigurer {
1314

15+
@Value("${cors.allow-url}")
16+
private String allowUrl;
17+
1418
@Value("${photo.upload.base-dir}")
1519
private String baseDir;
1620

21+
@Override
22+
public void addCorsMappings(CorsRegistry registry) {
23+
registry.addMapping("/**")
24+
.allowedOrigins(allowUrl)
25+
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")
26+
.allowedHeaders("*")
27+
.allowCredentials(true)
28+
.maxAge(3600);
29+
}
30+
1731
@Override
1832
public void addResourceHandlers(ResourceHandlerRegistry registry) {
1933
registry.addResourceHandler("/images/**")

src/main/resources/application-dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ spring:
1717
photo:
1818
upload:
1919
base-dir: ${PHOTOS_UPLOAD_URL}
20+
21+
cors:
22+
allow-url: ${CORS_ALLOW_URL}

src/main/resources/application-local-example.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ spring:
88
photo:
99
upload:
1010
base-dir: url
11+
12+
cors:
13+
allow-url: url

0 commit comments

Comments
 (0)