Skip to content

Commit

Permalink
Merge pull request #585 from gobitfly/BIDS-3218-Token-Header-to-SSR-R…
Browse files Browse the repository at this point in the history
…equests

Bids-3218: Add Token header to SSR requests
  • Loading branch information
benji-bitfly authored Jul 15, 2024
2 parents dac0816 + 524a1d2 commit e2bb834
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions frontend/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ NUXT_PUBLIC_V1_DOMAIN: ""
NUXT_PUBLIC_LOG_FILE: ""
NUXT_PUBLIC_CHAIN_ID_BY_DEFAULT: ""
NUXT_PUBLIC_MAINTENANCE_TS: "1717700652"
PRIVATE_SSR_SECRET: ""
6 changes: 6 additions & 0 deletions frontend/composables/useCustomFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function useCustomFetch () {
const { public: { apiClient, legacyApiClient, apiKey, domain, logIp }, private: pConfig } = runtimeConfig
const path = map.mock ? `${pathName}.json` : map.getPath?.(pathValues) || map.path
let baseURL = map.mock ? '../mock' : map.legacy ? legacyApiClient : apiClient
const ssrSecret = pConfig?.ssrSecret

if (process.server) {
baseURL = map.mock ? `${domain || url.origin.replace('http:', 'https:')}/mock` : map.legacy ? pConfig?.legacyApiServer : pConfig?.apiServer
Expand All @@ -47,6 +48,11 @@ export function useCustomFetch () {
if (apiKey) {
options.headers.append('Authorization', `Bearer ${apiKey}`)
}

if (process.server && ssrSecret) {
options.headers.append('x-ssr-secret', ssrSecret)
}

options.query = { ...options.query, ...query }
options.credentials = 'include'
const method = options.method || map.method || 'GET'
Expand Down
3 changes: 2 additions & 1 deletion frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default defineNuxtConfig({
},
private: {
apiServer: process.env.PRIVATE_API_SERVER,
legacyApiServer: process.env.PRIVATE_LEGACY_API_SERVER
legacyApiServer: process.env.PRIVATE_LEGACY_API_SERVER,
ssrSecret: process.env.PRIVATE_SSR_SECRET || ''
}
},
css: ['~/assets/css/main.scss', '~/assets/css/prime.scss', '@fortawesome/fontawesome-svg-core/styles.css'],
Expand Down

0 comments on commit e2bb834

Please sign in to comment.