Skip to content

Commit

Permalink
chore: update frontend environment variables (#3030)
Browse files Browse the repository at this point in the history
* Updated frontend environment variables and their corresponding doocumentation

* fixed import issue of kratos admin url

* Cookie 'secure' attr. set to true by default, removed unnecessary docker environment variables
  • Loading branch information
oana-lolea authored Nov 5, 2024
1 parent dc6fcf2 commit d30deeb
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const messageStorage = createCookieSessionStorage<
sameSite: 'lax',
maxAge: ONE_MINUTE_IN_S,
secrets: ['MY_SUPER_SECRET_TOKEN'],
secure: process.env.ENABLE_INSECURE_MESSAGE_COOKIE
? !parseBool(process.env.ENABLE_INSECURE_MESSAGE_COOKIE)
: process.env.NODE_ENV === 'production'
secure:
process.env.ENABLE_INSECURE_MESSAGE_COOKIE !== undefined
? !parseBool(process.env.ENABLE_INSECURE_MESSAGE_COOKIE)
: true
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import { readFileSync } from 'fs'
import { loadOrGenerateKey } from '@interledger/http-signature-utils'
import type { Config } from 'mock-account-service-lib'

if (!process.env.OPEN_PAYMENTS_URL) {
throw new Error('Environment variable OPEN_PAYMENTS_URL is required')
}

if (!process.env.GRAPHQL_URL) {
throw new Error('Environment variable GRAPHQL_URL is required')
}

if (!process.env.IDP_SECRET) {
throw new Error('environment variable IDP_SECRET is required')
throw new Error('Environment variable IDP_SECRET is required')
}

export const CONFIG: Config = {
Expand All @@ -14,9 +22,9 @@ export const CONFIG: Config = {
).toString('utf8')
),
key: loadOrGenerateKey(process.env.KEY_FILE),
publicHost: process.env.OPEN_PAYMENTS_URL ?? '',
publicHost: process.env.OPEN_PAYMENTS_URL,
testnetAutoPeerUrl: process.env.TESTNET_AUTOPEER_URL ?? '',
authServerDomain: process.env.AUTH_SERVER_DOMAIN || 'http://localhost:3006',
graphqlUrl: process.env.GRAPHQL_URL ?? '',
graphqlUrl: process.env.GRAPHQL_URL,
idpSecret: process.env.IDP_SECRET
}
5 changes: 4 additions & 1 deletion localenv/mock-account-servicing-entity/app/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export const parseBool = (str: string) => {
}

export function getOpenPaymentsUrl() {
if (!process.env.OPEN_PAYMENTS_URL) {
throw new Error('Environment variable OPEN_PAYMENTS_URL is missing')
}
if (typeof window === 'undefined') {
return process.env.OPEN_PAYMENTS_URL ?? 'https://cloud-nine-wallet-backend/'
return process.env.OPEN_PAYMENTS_URL
}

return window.ENV.OPEN_PAYMENTS_URL
Expand Down
12 changes: 6 additions & 6 deletions packages/documentation/src/partials/frontend-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { LinkOut } from '@interledger/docs-design-system'

<div class="overflow-table wider-column">

| Variable | Helm Value Name | Default | Description |
| -------------------------------- | -------------------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GRAPHQL_URL` | frontend.serviceUrls.GRAPHQL_URL | `http://localhost:3001/graphql` | URL for the GraphQL Admin API |
| `OPEN_PAYMENTS_URL` | frontend.serviceUrls.OPEN_PAYMENTS_URL | `http://localhost:3003/` | Open Payments API Endpoint |
| `PORT` | frontend.port | `3005` | Port from which to host the Remix app |
| `ENABLE_INSECURE_MESSAGE_COOKIE` | | _undefined_ | Values of `true`, `t`, `1` will not use a `secure` message cookie which is required for flash messages to work over http. When not set, the secure flag is set according to `NODE_ENV`. |
| Variable | Helm Value Name | Default | Description |
| -------------------------------- | -------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GRAPHQL_URL` | frontend.serviceUrls.GRAPHQL_URL | _undefined_ | URL for the GraphQL Admin API and it's required |
| `OPEN_PAYMENTS_URL` | frontend.serviceUrls.OPEN_PAYMENTS_URL | _undefined_ | Open Payments API Endpoint and it's required |
| `PORT` | frontend.port | `3005` | Port from which to host the Remix app |
| `ENABLE_INSECURE_MESSAGE_COOKIE` | | true | Values of `true`, `t`, `1` will not use a `secure` message cookie which is required for flash messages to work over http. When not set, the secure flag is set to true. |

</div>
2 changes: 1 addition & 1 deletion packages/frontend/app/lib/apollo.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const authLink = setContext((request, { headers }) => {
})

const httpLink = createHttpLink({
uri: process.env.GRAPHQL_URL ?? 'http://localhost:3001/graphql'
uri: process.env.GRAPHQL_URL
})

if (!global.__apolloClient) {
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/app/lib/envConfig.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const variables = {
? parseBool(process.env.AUTH_ENABLED)
: true,
kratosContainerPublicUrl: process.env.KRATOS_CONTAINER_PUBLIC_URL,
kratosBrowserPublicUrl: process.env.KRATOS_BROWSER_PUBLIC_URL
kratosBrowserPublicUrl: process.env.KRATOS_BROWSER_PUBLIC_URL,
kratosAdminUrl: process.env.KRATOS_ADMIN_URL
}

if (variables.authEnabled) {
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend/app/lib/message.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const messageStorage = createCookieSessionStorage<
sameSite: 'lax',
maxAge: ONE_MINUTE_IN_S,
secrets: ['MY_SUPER_SECRET_TOKEN'],
secure: process.env.ENABLE_INSECURE_MESSAGE_COOKIE
? !parseBool(process.env.ENABLE_INSECURE_MESSAGE_COOKIE)
: process.env.NODE_ENV === 'production'
secure:
process.env.ENABLE_INSECURE_MESSAGE_COOKIE !== undefined
? !parseBool(process.env.ENABLE_INSECURE_MESSAGE_COOKIE)
: true
}
})

Expand Down
6 changes: 5 additions & 1 deletion packages/frontend/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ export function capitalize(str: string) {
}

export function getOpenPaymentsUrl() {
if (!process.env.OPEN_PAYMENTS_URL) {
throw new Error('Environment variable OPEN_PAYMENTS_URL is missing')
}

if (typeof window === 'undefined') {
return process.env.OPEN_PAYMENTS_URL ?? 'https://cloud-nine-wallet-backend/'
return process.env.OPEN_PAYMENTS_URL
}

return window.ENV.OPEN_PAYMENTS_URL
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "tsc ./kratos/scripts/*.ts --esModuleInterop --outDir ./build && remix dev",
"lint:fix": "eslint --fix app/",
"lint:check": "eslint app/",
"start": "ENABLE_INSECURE_MESSAGE_COOKIE=true remix-serve ./build/index.js",
"start": "remix-serve ./build/index.js",
"typecheck": "tsc"
},
"dependencies": {
Expand Down

0 comments on commit d30deeb

Please sign in to comment.