Skip to content

Commit bb78812

Browse files
onmaxfarnabaz
andauthored
fix(nuxthub): register sql_dump route even if the database is disabled (#3668)
Co-authored-by: Farnabaz <farnabaz@gmail.com>
1 parent 7091d64 commit bb78812

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/presets/nuxthub.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,30 @@ export default definePreset({
1212
name: 'nuxthub',
1313
async setup(options, nuxt, config) {
1414
const nuxtOptions = nuxt.options as unknown as { hub: { db?: string | object | false, database?: boolean } }
15-
if (!nuxtOptions.hub?.db && !nuxtOptions.hub?.database) {
16-
logger.warn('NuxtHub dedected but the database is not enabled. Using local SQLite as default database instead.')
17-
return
18-
}
19-
20-
const runtimeConfig = nuxt.options.runtimeConfig as unknown as { hub: { db?: boolean | { driver: string, connection: { url?: string } }, database?: boolean | { driver: string, connection: { url?: string } } } }
21-
// Read from the final hub database configuration
22-
const hubDb = runtimeConfig.hub.db || runtimeConfig.hub.database
23-
// NuxtHub <= 0.9
24-
if (nuxtOptions.hub?.database === true) {
25-
options.database ||= { type: 'd1', bindingName: 'DB' }
26-
}
27-
else if (typeof nuxtOptions.hub?.db === 'string' && typeof hubDb === 'object') {
28-
if (hubDb.driver === 'd1') {
15+
if (nuxtOptions.hub?.db || nuxtOptions.hub?.database) {
16+
const runtimeConfig = nuxt.options.runtimeConfig as unknown as { hub: { db?: boolean | { driver: string, connection: { url?: string } }, database?: boolean | { driver: string, connection: { url?: string } } } }
17+
// Read from the final hub database configuration
18+
const hubDb = runtimeConfig.hub.db || runtimeConfig.hub.database
19+
// NuxtHub <= 0.9
20+
if (nuxtOptions.hub?.database === true) {
2921
options.database ||= { type: 'd1', bindingName: 'DB' }
3022
}
31-
else if (hubDb.driver === 'node-postgres') {
32-
options.database ||= { type: 'postgresql', url: hubDb.connection.url as string }
33-
}
34-
else {
35-
options.database ||= { type: hubDb.driver as 'sqlite' | 'postgresql' | 'postgres' | 'libsql' | 'pglite', ...hubDb.connection } as unknown as SqliteDatabaseConfig | LibSQLDatabaseConfig | PGliteDatabaseConfig
23+
else if (typeof nuxtOptions.hub?.db === 'string' && typeof hubDb === 'object') {
24+
if (hubDb.driver === 'd1') {
25+
options.database ||= { type: 'd1', bindingName: 'DB' }
26+
}
27+
else if (hubDb.driver === 'node-postgres') {
28+
options.database ||= { type: 'postgresql', url: hubDb.connection.url as string }
29+
}
30+
else {
31+
options.database ||= { type: hubDb.driver as 'sqlite' | 'postgresql' | 'postgres' | 'libsql' | 'pglite', ...hubDb.connection } as unknown as SqliteDatabaseConfig | LibSQLDatabaseConfig | PGliteDatabaseConfig
32+
}
3633
}
3734
}
35+
else {
36+
logger.warn('NuxtHub dedected but the database is not enabled. Using local SQLite as default database instead.')
37+
}
38+
3839
const preset = (process.env.NITRO_PRESET || nuxt.options.nitro.preset || provider).replace(/_/g, '-')
3940
if (preset.includes('cloudflare')) {
4041
await cloudflarePreset.setup?.(options, nuxt, config)

0 commit comments

Comments
 (0)