Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 fix ssr for graphql endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Ruck committed Nov 1, 2023
1 parent 9ea8af9 commit c3586fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
APP_API_URL=https://internal.api.democracy-app.de
NEXT_PUBLIC_APP_URL=http://localhost:3000
HOSTNAME=localhost
PROTOCOL=http
PORT=3000
15 changes: 10 additions & 5 deletions src/utils/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import { offsetLimitPagination } from '@apollo/client/utilities';
import DebounceLink from 'apollo-link-debounce';

export default function getClient() {
const isServer = typeof window === 'undefined';
const host = isServer ? process.env.HOSTNAME : window.location.origin;
const port = isServer ? process.env.PORT : window.location.port;
const protocol = isServer ? process.env.PROTOCOL : window.location.protocol;
const url =
process.env.NODE_ENV === 'production'
? `${protocol}://${host}`
: `${protocol}://${host}:${port}`;

const link = ApolloLink.from([
new DebounceLink(100),
new HttpLink({
uri: `${
process.env.NODE_ENV === 'development'
? process.env.NEXT_PUBLIC_APP_URL
: ''
}/api/graphql`,
uri: `${url}/api/graphql`,
}),
]);

Expand Down

0 comments on commit c3586fa

Please sign in to comment.