Skip to content

Commit b4af946

Browse files
committed
[feat] 환경변수 설정
1 parent a7c8d12 commit b4af946

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

next.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { NextConfig } from 'next';
22

33
const nextConfig: NextConfig = {
4-
54
// webpack 설정
65
webpack: (config) => {
6+
env: {
7+
NPUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL;
8+
}
9+
710
// @ts-expect-error 타입 에러 무시
811
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'));
912

@@ -37,7 +40,7 @@ const nextConfig: NextConfig = {
3740
loaders: ['@svgr/webpack'],
3841
as: '*.js',
3942
},
40-
}
43+
},
4144
},
4245
};
4346

src.zip

997 KB
Binary file not shown.

src/app/api/config/appConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const getApi =
2+
process.env.NODE_ENV === 'development'
3+
? process.env.NEXT_PUBLIC_API_URL_DEV
4+
: process.env.NEXT_PUBLIC_API_URL_PROD;

src/domains/community/api/fetchComment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import { getApi } from '@/app/api/config/appConfig';
12
import { Post } from '../types/post';
23

34
export const fetchComment = async (postId: number): Promise<Post[] | null> => {
45
try {
5-
const res = await fetch(`http://localhost:8080/posts/${postId}/comments`, {
6+
const res = await fetch(`${getApi}posts/${postId}/comments`, {
67
method: 'GET',
78
});
89
const data = await res.json();
9-
console.log(data);
1010
return data.data;
1111
} catch (err) {
1212
console.error('해당 글의 댓글 조회 실패', err);

src/domains/community/api/fetchPost.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { getApi } from '@/app/api/config/appConfig';
12
import { Post } from '@/domains/community/types/post';
23

34
export const fetchPost = async (): Promise<Post[] | null> => {
45
try {
5-
const res = await fetch('http://localhost:8080/posts', {
6+
const res = await fetch(`${getApi}posts`, {
67
method: 'GET',
78
cache: 'no-store',
89
});

src/domains/community/main/PostCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function PostCard({ posts, setPosts }: Props) {
8181
postId={postId}
8282
/>
8383
</div>
84-
<figure className="flex items-center flex-shrink-0 w-[115px] h-[115px]">
84+
<figure className="flex items-center flex-shrink-0 md:w-[115px] md:h-[115px] w-[85px] h-[85px]">
8585
<Image
8686
src={prePost}
8787
alt="예비사진"

0 commit comments

Comments
 (0)