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

Commit

Permalink
fix: handle ssr for graphql endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Ruck <[email protected]>
  • Loading branch information
Manuel Ruck authored and ManAnRuck committed Nov 1, 2023
1 parent a978453 commit fe8bb27
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
4 changes: 1 addition & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
APP_API_URL=https://internal.api.democracy-app.de
HOSTNAME=localhost
PROTOCOL=http
PORT=3000
APP_HOST=http://localhost:3000
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_API_URL=https://internal.api.democracy-app.de
APP_HOST=http://localhost:3000
11 changes: 2 additions & 9 deletions src/utils/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ 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 host = isServer ? process.env.APP_HOST : window.location.origin;
const link = ApolloLink.from([
new DebounceLink(100),
new HttpLink({
uri: `${url}/api/graphql`,
uri: `${host}/api/graphql`,
}),
]);

Expand Down

0 comments on commit fe8bb27

Please sign in to comment.