Skip to content

Commit 3a73d23

Browse files
committed
chore: update query endpoint
1 parent fa6efdd commit 3a73d23

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/module.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ export default defineNuxtModule<ModuleOptions>({
196196
config.alias['#content/local-adapter'] = await resolveDatabaseAdapter(options._localDatabase!.type || 'sqlite', resolveOptions)
197197

198198
config.handlers ||= []
199-
config.handlers.push({
200-
route: '/__nuxt_content/:collection/query',
201-
handler: resolver.resolve('./runtime/api/query.post'),
199+
manifest.collections.forEach((collection) => {
200+
config.handlers!.push({
201+
route: `/__nuxt_content/${collection.name}/query`,
202+
handler: resolver.resolve('./runtime/api/query.post'),
203+
})
202204
})
203205

204206
// Handle HMR changes

src/presets/cloudflare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { collectionDumpTemplate } from '../utils/templates'
77
export default definePreset({
88
name: 'cloudflare',
99
setup(_options, _nuxt, { resolver, manifest }) {
10-
manifest.collections.map(async (collection) => {
10+
manifest.collections.map((collection) => {
1111
addServerHandler({
1212
route: `/__nuxt_content/${collection.name}/sql_dump.txt`,
1313
handler: resolver.resolve('./runtime/presets/cloudflare/database-handler'),

src/presets/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default definePreset({
88
// Due to prerender enabling in the module, Nuxt create a route for each collection
99
// These routes cause issue while enabling cache in Nuxt.
1010
// So we need to add a server handler for each collection to handle the request.
11-
manifest.collections.map(async (collection) => {
11+
manifest.collections.map((collection) => {
1212
addServerHandler({
1313
route: `/__nuxt_content/${collection.name}/sql_dump.txt`,
1414
handler: resolver.resolve('./runtime/presets/node/database-handler'),

src/runtime/api/query.post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useRuntimeConfig } from '#imports'
66

77
export default eventHandler(async (event) => {
88
const { sql } = await readBody(event)
9-
const collection = getRouterParam(event, 'collection')!
9+
const collection = getRouterParam(event, 'collection')! || event.path?.split('/')?.[2] || ''
1010

1111
assertSafeQuery(sql, collection)
1212

0 commit comments

Comments
 (0)