Skip to content

Commit

Permalink
Merge pull request #706 from davidktlee/fix-notification
Browse files Browse the repository at this point in the history
fix: 알림 요청 api url 수정
  • Loading branch information
hatchling13 authored Mar 28, 2024
2 parents 3fda3ba + f6f657e commit 7c8d4d1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
13 changes: 9 additions & 4 deletions frontend/src/app/(with-header)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import type { ReactNode } from 'react';
import '../globals.css';
import Header from '../_components/header/Header';
import NextPublicProvider from '@/context/NextPublicContext';

export default async function WithHeaderLayout({
children,
}: {
children: ReactNode;
}) {
const { DEV_BASE_URL, BASE_URL, ENVIRONMENT } = process.env;
const currentBaseUrl = ENVIRONMENT === 'production' ? BASE_URL : DEV_BASE_URL;
return (
<section className="w-full h-full flex flex-col">
<Header />
{children}
</section>
<NextPublicProvider nextBaseUrl={currentBaseUrl}>
<section className="w-full h-full flex flex-col">
<Header />
{children}
</section>
</NextPublicProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Bell from '/public/icons/bell.svg';
import { useRouter } from 'next/navigation';
import ToastMsg from '../ui/toast/ToastMsg';
import { MemberContext } from '@/context/MemberContext';
import { NextPublicContext } from '@/context/NextPublicContext';

const BASE_URL =
process.env.ENVIRONMENT === 'production'
Expand All @@ -16,11 +17,12 @@ export default function NotificationIcon() {
const [errorText, setErrorText] = useState('');

const user = memberStatus.isLoggedIn === 'true' ? memberStatus.member : null;
const baseUrl = useContext(NextPublicContext);

useEffect(() => {
if (user) {
const eventSource = new EventSource(
`${BASE_URL}/v1/notifications/stream/${user?.member_id}`,
`${baseUrl}/v1/notifications/stream/${user?.member_id}`,
);

eventSource.addEventListener('notification', (e) => {
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/context/NextPublicContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client';
import { ReactElement, createContext } from 'react';

export const NextPublicContext = createContext<string>('');

export default function NextPublicProvider({
children,
nextBaseUrl,
}: {
children: ReactElement;
nextBaseUrl: string;
}) {
return (
<NextPublicContext.Provider value={nextBaseUrl}>
{children}
</NextPublicContext.Provider>
);
}

0 comments on commit 7c8d4d1

Please sign in to comment.