Skip to content

Commit

Permalink
fix(nuxthub): ensure database is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Jan 31, 2025
1 parent ad45699 commit b46fc37
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ export default defineNuxtModule<ModuleOptions>({
}

// Load nitro preset and set db adapter
const preset = findPreset(nuxt)
await preset?.setup?.(options, nuxt)
nuxt.hook('nitro:config', async (config) => {
const preset = findPreset(nuxt)
await preset.setupNitro(config, { manifest, resolver, moduleOptions: options })
Expand Down
5 changes: 5 additions & 0 deletions src/presets/nuxthub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import cfPreset from './cloudflare-pages'

export default definePreset({
name: 'nuxthub',
async setup(options, nuxt) {
// Make sure database is enabled
const nuxthubOptions: { database?: boolean } = (nuxt.options as unknown as { hub: unknown }).hub ||= {}
nuxthubOptions.database = true
},
async setupNitro(nitroConfig, options) {
await cfPreset.setupNitro(nitroConfig, options)

Expand Down
2 changes: 2 additions & 0 deletions src/utils/preset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NitroConfig } from 'nitropack'
import type { Resolver } from '@nuxt/kit'
import type { Nuxt } from '@nuxt/schema'
import type { ModuleOptions } from '../types/module'
import type { Manifest } from '../types/manifest'

Expand All @@ -10,6 +11,7 @@ interface Options {
}
export interface Preset {
name: string
setup?: (options: ModuleOptions, nuxt: Nuxt) => Promise<void>
setupNitro: (nitroConfig: NitroConfig, opts: Options) => void | Promise<void>
}

Expand Down

0 comments on commit b46fc37

Please # to comment.