Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
fix: websocket uri (#525)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Burtey <[email protected]>
  • Loading branch information
nicolasburtey and Nicolas Burtey authored Jul 27, 2023
1 parent d02959f commit a79fe11
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
let GRAPHQL_HOSTNAME = process.env.NEXT_PUBLIC_GRAPHQL_HOSTNAME as string
const GRAPHQL_WEBSOCKET_URL = process.env.NEXT_PUBLIC_GRAPHQL_WEBSOCKET_URL ?? ""
let GRAPHQL_HOSTNAME = process.env.NEXT_PUBLIC_GRAPHQL_HOSTNAME
let GRAPHQL_WEBSOCKET_URL = process.env.NEXT_PUBLIC_GRAPHQL_WEBSOCKET_URL ?? ""

// we need an internal dns to properly propagate the ip related headers to api
// if we use the api endpoints, nginx will rewrite the header to prevent spoofing
// for example: "api.galoy-name-galoy.svc.cluster.local"
const GRAPHQL_HOSTNAME_INTERNAL = process.env.GRAPHQL_HOSTNAME_INTERNAL as string
const GRAPHQL_URI_INTERNAL = `http://${GRAPHQL_HOSTNAME_INTERNAL}/graphql`

// from https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
// Note: After being built, your app will no longer respond to changes to these environment variables.
// For instance, if you use a Heroku pipeline to promote slugs built in one environment to another environment,
// or if you build and deploy a single Docker image to multiple environments, all NEXT_PUBLIC_ variables will be frozen with the value evaluated at build time,
// so these values need to be set appropriately when the project is built. If you need access to runtime environment values,
// you'll have to setup your own API to provide them to the client (either on demand or during initialization).

// FIXME: remove once dns has been migrated out of ln.bitcoinbeach.com
// so we always assume the api is on the same domain as the frontend
if (!GRAPHQL_HOSTNAME) {
if (typeof window !== "undefined") {
let hostParts = window.location.host.split(".")
if (hostParts.length <= 3) {
// throw new Error("Missing env variables")
hostParts = "pay.mainnet.galoy.io".split(".")
}
const hostParts = window.location.host.split(".")

hostParts[0] = "api"
GRAPHQL_HOSTNAME = hostParts.join(".")

hostParts[0] = "ws"
GRAPHQL_WEBSOCKET_URL = `wss://${hostParts.join(".")}/graphql`
} else {
GRAPHQL_HOSTNAME = "api.mainnet.galoy.io"
alert("window is undefined")
}
}

const GRAPHQL_URI_INTERNAL = `http://${GRAPHQL_HOSTNAME_INTERNAL}/graphql`
const GRAPHQL_URI = `https://${GRAPHQL_HOSTNAME}/graphql`
const GRAPHQL_SUBSCRIPTION_URI = `${GRAPHQL_WEBSOCKET_URL}` // 'wss://ws.staging.galoy.io/graphql'
const GRAPHQL_SUBSCRIPTION_URI = GRAPHQL_WEBSOCKET_URL

const NOSTR_PUBKEY = process.env.NOSTR_PUBKEY as string

Expand Down

0 comments on commit a79fe11

Please sign in to comment.