Skip to content

Commit

Permalink
Merge pull request #100 from prgrms-web-devcourse-final-project/hotfix
Browse files Browse the repository at this point in the history
feat: http error
  • Loading branch information
minjeongss authored Dec 5, 2024
2 parents da00236 + 30da31f commit 0a09564
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
39 changes: 39 additions & 0 deletions app/api/invite/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NextRequest, NextResponse } from 'next/server';
import { API_BASE_URL } from '@/config/apiEndPointConfig';
import axiosInstance from '@/lib/axios';

export async function GET(request: NextRequest) {
try {
// URLμ—μ„œ 검색어 νŒŒλΌλ―Έν„° μΆ”μΆœ
const { searchParams } = new URL(request.url);
const queryString = searchParams.get('string');

if (!queryString) {
return NextResponse.json(
{ error: '검색어가 ν•„μš”ν•©λ‹ˆλ‹€.' },
{ status: 400 }
);
}

const response = await axiosInstance.get(
`${API_BASE_URL.DNS}/api/user-service/nickname`,
{
params: {
string: queryString,
},
headers: {
'Content-Type': 'application/json',
},
}
);

console.log('Search response:', response.data);
return NextResponse.json(response.data);
} catch (error) {
console.error('Search error in API route:', error);
return NextResponse.json(
{ error: 'μ‚¬μš©μž 검색에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.' },
{ status: 500 }
);
}
}
16 changes: 6 additions & 10 deletions components/Layout/MakeRoom/FriendsInviteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import toast from 'react-hot-toast';
import useUserStore from '@stores/useUserStore';
import InviteButton from '@layout/MakeRoom/InviteButton';
import { API_BASE_URL } from '@/config/apiEndPointConfig';

interface UserInfo {
id: number;
Expand Down Expand Up @@ -44,15 +43,12 @@ const FriendsInviteForm = ({
if (searchTerm.trim()) {
try {
const queryString = encodeURIComponent(searchTerm.trim());
const response = await fetch(
`${API_BASE_URL.DNS}/api/user-service/nickname?string=${queryString}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}
);
const response = await fetch(`/api/invite?string=${queryString}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (response.status === 200) {
const data = await response.json();
Expand Down

0 comments on commit 0a09564

Please sign in to comment.