Skip to content

Commit

Permalink
fix(prerender): add extension to pre-rendered queries (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Sep 7, 2022
1 parent ee3da84 commit 6c5350a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/runtime/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import type { NavItem, QueryBuilder, QueryBuilderParams } from '../types'
import { jsonStringify } from '../utils/json'
import { withContentBase } from './utils'

export const fetchContentNavigation = (queryBuilder?: QueryBuilder | QueryBuilderParams) => {
export const fetchContentNavigation = (queryBuilder?: QueryBuilder | QueryBuilderParams): Promise<Array<NavItem>> => {
let params = queryBuilder

// When params is an instance of QueryBuilder then we need to pick the params explicitly
if (typeof params?.params === 'function') { params = params.params() }

const apiPath = withContentBase(params ? `/navigation/${hash(params)}` : '/navigation')
const apiPath = withContentBase(params ? `/navigation/${hash(params)}.json` : '/navigation')

// Add `prefetch` to `<head>` in production
if (!process.dev && process.server) {
Expand All @@ -21,7 +21,7 @@ export const fetchContentNavigation = (queryBuilder?: QueryBuilder | QueryBuilde
})
}

return $fetch<Array<NavItem>>(apiPath, {
return $fetch(apiPath, {
method: 'GET',
responseType: 'json',
params: {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const createQueryFetch = <T = ParsedContent>(path?: string) => (query: Qu

const params = query.params()

const apiPath = withContentBase(process.dev ? '/query' : `/query/${hash(params)}`)
const apiPath = withContentBase(process.dev ? '/query' : `/query/${hash(params)}.json`)

// Prefetch the query
if (!process.dev && process.server) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const parseQueryParams = (body: string) => {

const memory = {}
export const getContentQuery = (event: CompatibilityEvent): QueryBuilderParams => {
const { qid } = event.context.params
const qid = event.context.params.qid?.replace(/.json$/, '')
const query: any = useQuery(event) || {}

// Using /api/_content/query/:qid?_params=....
Expand Down

0 comments on commit 6c5350a

Please sign in to comment.