Skip to content

Commit

Permalink
fix: nextjs env
Browse files Browse the repository at this point in the history
  • Loading branch information
cooderl committed Feb 29, 2024
1 parent 0013132 commit ec81506
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/web/app/feeds/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { toast } from 'sonner';
import { PlusIcon } from '@web/components/PlusIcon';
import dayjs from 'dayjs';
import { useParams } from 'next/navigation';
import { getServerOriginUrl } from '../utils';

const serverOriginUrl = process.env.NEXT_PUBLIC_SERVER_ORIGIN_URL;

Expand Down Expand Up @@ -206,7 +207,7 @@ const FeedLayout = ({
size="sm"
showAnchorIcon
target="_blank"
href={`${serverOriginUrl}/feeds/${currentMpInfo.id}`}
href={`${getServerOriginUrl()}/feeds/${currentMpInfo.id}`}
color="foreground"
>
RSS
Expand All @@ -217,7 +218,7 @@ const FeedLayout = ({
size="sm"
showAnchorIcon
target="_blank"
href={`${serverOriginUrl}/feeds/all.atom`}
href={`${getServerOriginUrl()}/feeds/all.atom`}
color="foreground"
>
RSS
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Nav from '@web/components/Nav';
import { useLayoutEffect } from 'react';
import { getAuthCode } from './utils';
import { useRouter } from 'next/navigation';
import { PublicEnvScript } from 'next-runtime-env';

export default function RootLayout({
children,
Expand All @@ -27,6 +28,7 @@ export default function RootLayout({
<title>WeWe-RSS</title>
<meta name="description" content="更好的公众号订阅方式" />
<link rel="icon" href="https://r2-assets.111965.xyz/wewe-rss.png" />
<PublicEnvScript />
</head>

<body>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/trpc-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { trpc } from './trpc';
import { AppRouter } from '@server/trpc/trpc.router';
import { toast } from 'sonner';
import { useRouter } from 'next/navigation';
import { setAuthCode } from './utils';
import { getServerOriginUrl, setAuthCode } from './utils';

const serverOriginUrl = process.env.NEXT_PUBLIC_SERVER_ORIGIN_URL;

Expand Down Expand Up @@ -91,7 +91,7 @@ export const TrpcProvider: React.FC<{ children: React.ReactNode }> = ({
enabled: () => true,
}),
httpBatchLink({
url: serverOriginUrl + '/trpc',
url: getServerOriginUrl() + '/trpc',
async headers() {
const token = localStorage.getItem('authCode') || '';

Expand Down
6 changes: 6 additions & 0 deletions apps/web/app/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { env } from 'next-runtime-env';

export const getAuthCode = () => {
return window.localStorage.getItem('authCode') || '';
};

export const setAuthCode = (authCode: string) => {
window.localStorage.setItem('authCode', authCode);
};

export const getServerOriginUrl = () => {
return env('NEXT_PUBLIC_SERVER_ORIGIN_URL');
};
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dayjs": "^1.11.10",
"framer-motion": "^11.0.5",
"next": "14.1.0",
"next-runtime-env": "^3.2.0",
"next-themes": "^0.2.1",
"qrcode.react": "^3.1.0",
"react": "^18",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ec81506

Please sign in to comment.