Skip to content

Commit

Permalink
Merge pull request #56 from capstone-maru/feat/geocoding-api
Browse files Browse the repository at this point in the history
feat: hide the secret value of the geocoding API
  • Loading branch information
cjeongmin authored Apr 16, 2024
2 parents 408c7ef + 3f7a779 commit e6afeb3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 28 deletions.
7 changes: 1 addition & 6 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ const nextConfig = {
async rewrites() {
return [
{
source: '/api/:path*',
source: '/maru-api/:path*',
destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`,
},
{
source: '/naveropenapi/:path*',
destination:
'https://naveropenapi.apigw.ntruss.com/map-geocode/v2/:path*',
},
];
},
trailingSlash: false /* 만약, 후행 슬래시가 필요하다면 true, default → false */,
Expand Down
28 changes: 28 additions & 0 deletions src/app/api/geocode/[query]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import axios from 'axios';
import { NextResponse, type NextRequest } from 'next/server';

import { type FromAddrToCoordDTO } from '@/features/geocoding';

export async function GET(
request: NextRequest,
{ params: { query } }: { params: { query: string } },
) {
try {
const response = await axios.get<FromAddrToCoordDTO>(
`https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=${query}`,
{
headers: {
'X-NCP-APIGW-API-KEY-ID': process.env.NEXT_PUBLIC_NAVER_MAP_CLIENT_ID,
'X-NCP-APIGW-API-KEY':
process.env.NEXT_PUBLIC_NAVER_MAP_CLIENT_SECRET,
},
},
);

return new NextResponse(JSON.stringify(response.data), { status: 200 });
} catch (error) {
return new NextResponse(JSON.stringify({ success: false }), {
status: 400,
});
}
}
6 changes: 3 additions & 3 deletions src/features/auth/auth.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { type PostTokenRefreshDTO, type GetUserDataDTO } from './auth.dto';

export const getUserData = async () =>
await axios
.get<GetUserDataDTO>('/api/auth/initial/info')
.get<GetUserDataDTO>('/maru-api/auth/initial/info')
.then(response => response.data);

export const postTokenRefresh = async (refreshToken: string) =>
await axios
.post<PostTokenRefreshDTO>(
'/api/auth/token/refresh',
'/maru-api/auth/token/refresh',
{},
{ headers: { Authorization: `Bearer ${refreshToken}` } },
)
.then(response => response.data);

export const getAuthLogout = async (refreshToken: string) =>
await axios.get('/api/auth/logout', {
await axios.get('/maru-api/auth/logout', {
headers: { Authorization: `Bearer ${refreshToken}` },
});
7 changes: 1 addition & 6 deletions src/features/geocoding/geocoding.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import axios from 'axios';
import { type FromAddrToCoordDTO } from '@/features/geocoding/geocoding.type';

export const fromAddrToCoord = async ({ query }: { query: string }) =>
await axios.get<FromAddrToCoordDTO>(`/naveropenapi/geocode?query=${query}`, {
headers: {
'X-NCP-APIGW-API-KEY-ID': process.env.NEXT_PUBLIC_NAVER_MAP_CLIENT_ID,
'X-NCP-APIGW-API-KEY': process.env.NEXT_PUBLIC_NAVER_MAP_CLIENT_SECRET,
},
});
await axios.get<FromAddrToCoordDTO>(`/api/geocode/${query}`);

export const getGeolocation = ({
onSuccess,
Expand Down
2 changes: 1 addition & 1 deletion src/features/image/image.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type GetImageURLDTO } from './image.dto';

export const getImageURL = async (fileExtension: string) =>
await axios.get<GetImageURLDTO>(
`/api/image/upload?extension=${fileExtension}`,
`/maru-api/image/upload?extension=${fileExtension}`,
);

export const putImage = async (url: string, image: File) =>
Expand Down
14 changes: 7 additions & 7 deletions src/features/profile/profile.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {

export const getUserProfileData = async (memberId: string) =>
await axios
.get<GetUserProfileDTO>(`/api/profile/${memberId}`)
.get<GetUserProfileDTO>(`/maru-api/profile/${memberId}`)
.then(res => res.data);

export const getUserCard = async (cardId: number) =>
await axios
.get<GetUserCardDTO>(`/api/profile/card/${cardId}`)
.get<GetUserCardDTO>(`/maru-api/profile/card/${cardId}`)
.then(res => res.data);

export const putUserCard = async (
Expand All @@ -24,9 +24,9 @@ export const putUserCard = async (
features: Array<string | undefined>,
) =>
await axios
.put<PutUserCardDTO>(`/api/profile/${cardId}`, {
location: location,
features: features,
.put<PutUserCardDTO>(`/maru-api/profile/${cardId}`, {
location,
features,
})
.then(res => {
console.log(res.data);
Expand All @@ -35,11 +35,11 @@ export const putUserCard = async (

export const getFollowingListData = async () =>
await axios
.get<GetFollowingListDTO>(`/api/profile/follow`)
.get<GetFollowingListDTO>(`/maru-api/profile/follow`)
.then(res => res.data);

export const postFollowData = async (memberId: string) => {
await axios
.post<PostFollowDTO>(`/api/profile/${memberId}/follow`, {})
.post<PostFollowDTO>(`/maru-api/profile/${memberId}/follow`, {})
.then(res => res.data);
};
12 changes: 7 additions & 5 deletions src/features/shared/shared.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getSharedPosts = async ({
page,
}: GetSharedPostsProps) => {
const getURI = () => {
const baseURL = '/api/shared/posts/studio';
const baseURL = '/maru-api/shared/posts/studio';
let query = '';

if (filter !== undefined) {
Expand Down Expand Up @@ -71,7 +71,7 @@ export const createSharedPost = async ({
formData.append('locationData', JSON.stringify(locationData));

return await axios.post<SuccessBaseDTO>(
`/api/shared/posts/studio`,
`/maru-api/shared/posts/studio`,
formData,
{
headers: { 'Content-Type': 'multipart/form-data' },
Expand All @@ -80,10 +80,12 @@ export const createSharedPost = async ({
};

export const getSharedPost = async (postId: number) =>
await axios.get<GetSharedPostDTO>(`/api/shared/posts/studio/${postId}`);
await axios.get<GetSharedPostDTO>(`/maru-api/shared/posts/studio/${postId}`);

export const deleteSharedPost = async (postId: number) =>
await axios.delete<SuccessBaseDTO>(`/api/shared/posts/studio/${postId}`);
await axios.delete<SuccessBaseDTO>(`/maru-api/shared/posts/studio/${postId}`);

export const scrapPost = async (postId: number) =>
await axios.get<SuccessBaseDTO>(`/api/shared/posts/studio/${postId}/scrap`);
await axios.get<SuccessBaseDTO>(
`/maru-api/shared/posts/studio/${postId}/scrap`,
);

0 comments on commit e6afeb3

Please sign in to comment.