Skip to content

Commit

Permalink
feat: add quant useragent header for static build requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dylankelly committed Jan 29, 2025
1 parent 279e985 commit 280c801
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 1 addition & 2 deletions packages/nuxt-ripple/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export default defineNuxtConfig({
failOnError: false,
retryDelay: 6000,
retry: 2,
interval: 3000,
concurrency: 3
concurrency: 10
}
},
// defaults for static prerendering - can be overridden in the project
Expand Down
14 changes: 12 additions & 2 deletions packages/nuxt-ripple/server/api/tide/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'h3'
import { createHandler, TidePageApi } from '@dpc-sdp/ripple-tide-api'
import { BadRequestError } from '@dpc-sdp/ripple-tide-api/errors'
import { useNitroApp } from '#imports'
import { useNitroApp, useRuntimeConfig } from '#imports'
import { AuthCookieNames } from '@dpc-sdp/nuxt-ripple-preview/utils'

export const createPageHandler = async (
Expand Down Expand Up @@ -41,9 +41,19 @@ export const createPageHandler = async (
if (tokenCookie && !isTokenExpired) {
headers['X-OAuth2-Authorization'] = `Bearer ${tokenCookie}`
}
const {
public: { isStatic }
} = useRuntimeConfig()

if (isStatic) {
headers['user-agent'] = 'Quant;'
}

const sectionId = getHeader(event, 'x-section-request-id')
const path = query.path.length > 1 && query.path.charAt(query.path.length - 1) === '/' ? query.path.substring(0, query.path.length - 1) : query.path
const path =
query.path.length > 1 && query.path.charAt(query.path.length - 1) === '/'
? query.path.substring(0, query.path.length - 1)
: query.path

const pageResponse = await tidePageApi.getPageByPath(
path,
Expand Down
12 changes: 11 additions & 1 deletion packages/nuxt-ripple/server/api/tide/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ export const createSiteHandler = async (

const sectionId = getHeader(event, 'x-section-request-id')

const siteResponse = await tideSiteApi.getSiteData(query.id, sectionId)
const headers = {}

if (isStatic) {
headers['user-agent'] = 'Quant;'
}

const siteResponse = await tideSiteApi.getSiteData(
query.id,
sectionId,
headers
)

// Need to pass on the section cache tags to the nuxt app
if (siteResponse.headers && siteResponse.headers['section-cache-tags']) {
Expand Down
5 changes: 3 additions & 2 deletions packages/ripple-tide-api/src/services/tide-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class TideSite extends TideApiBase {
}
}

async getSiteData(siteid, logId?: string) {
async getSiteData(siteid, logId?: string, headers?: Record<string, string>) {
if (!this.siteMapping) {
throw new Error('Error loading site mapping')
}
Expand All @@ -43,10 +43,11 @@ export default class TideSite extends TideApiBase {
}
}
try {
const { data: response, headers } = await this.get(
const { data: response, headers = {} } = await this.get(
`/taxonomy_term/sites`,
{
params,
headers,
_logId: logId
}
)
Expand Down

0 comments on commit 280c801

Please sign in to comment.