Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prerender): add extension to prerendered queries #1456

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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