-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- kakao map image 조회를 위해 proxy endpoint 추가
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Controller, Get, Query, Response } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
|
||
import { Response as Res } from 'express'; | ||
|
||
import { ProxyService } from 'src/proxy/proxy.service'; | ||
|
||
@ApiTags('proxy') | ||
@Controller('proxy') | ||
export class ProxyController { | ||
constructor(private readonly proxyService: ProxyService) {} | ||
|
||
// TODO : 한정된 도메인에 대해서만 proxy 하도록 조건 추가 필요 | ||
@Get() | ||
async getKakaoImage(@Query('url') url: string, @Response() res: Res) { | ||
const result = await this.proxyService.fetchKakaoImage(url); | ||
|
||
res.setHeader('Content-Type', result.contentType); | ||
res.send(result.data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { ProxyController } from './proxy.controller'; | ||
import { ProxyService } from './proxy.service'; | ||
|
||
@Module({ | ||
imports: [HttpModule], | ||
controllers: [ProxyController], | ||
providers: [ProxyService], | ||
}) | ||
export class ProxyModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { HttpService } from '@nestjs/axios'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { map } from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class ProxyService { | ||
constructor(private readonly httpService: HttpService) {} | ||
|
||
// 카카오 API로부터 이미지를 가져오는 메서드 | ||
async fetchKakaoImage(url: string): Promise<any> { | ||
return this.httpService | ||
.get(url, { responseType: 'arraybuffer' }) | ||
.pipe( | ||
map((response) => ({ | ||
data: response.data, | ||
contentType: response.headers['content-type'], | ||
})), | ||
) | ||
.toPromise(); | ||
} | ||
} |