Skip to content

Commit

Permalink
chore: improve loggings
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Feb 5, 2024
1 parent 5223aef commit 77e6800
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 20 deletions.
18 changes: 6 additions & 12 deletions _nuxthub/modules/hub/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNuxtModule, createResolver } from 'nuxt/kit'
import { defineNuxtModule, createResolver, logger } from 'nuxt/kit'
import { join } from 'pathe'
import { defu } from 'defu'
import { mkdir, writeFile, readFile } from 'node:fs/promises'
Expand All @@ -10,20 +10,17 @@ export default defineNuxtModule({
async setup (_options, nuxt) {
const { resolve } = createResolver(import.meta.url)

// Add Server utils based on environment
// nuxt.options.nitro.imports = nuxt.options.nitro.imports || {}
// nuxt.options.nitro.imports.dirs = nuxt.options.nitro.imports.dirs || []
// nuxt.options.nitro.imports.dirs.push(resolve(`../server/_utils/${nuxt.options.dev ? 'dev' : 'prod'}/`))

// Production mode
if (!nuxt.options.dev) {
return
}

if (process.env.NUXT_HUB_URL) {
// TODO: check on hub.nuxt.com if the project is connected
// return
// return once we support Proxy for all providers (R2 missing now)
logger.info(`Using remote hub from \`${process.env.NUXT_HUB_URL}\``)
return
} else {
logger.info('Using local hub from bindings')
}

// Local development without remote connection
Expand Down Expand Up @@ -52,9 +49,6 @@ export default defineNuxtModule({
configPath: wranglerPath,
persistDir: hubDir
})
// Make sure runtime is transpiled
// nuxt.options.nitro.externals.inline = nuxt.options.nitro.externals.inline || []
// nuxt.options.nitro.externals.inline.push(resolve('./runtime/server'))
// Add server plugin
nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || []
nuxt.options.nitro.plugins.push(resolve('./runtime/server/plugins/cloudflare.dev'))
Expand All @@ -69,4 +63,4 @@ kv_namespaces = [
]
r2_buckets = [
{ binding = "BLOB", bucket_name = "default" },
]`
]`
3 changes: 0 additions & 3 deletions _nuxthub/server/utils/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export function useBlob () {
const proxyURL = import.meta.dev && process.env.NUXT_HUB_URL
let bucket: R2Bucket
if (!proxyURL) {
import.meta.dev && console.log('Using Blob local storage...')
bucket = _useBucket()
} else {
import.meta.dev && console.log('Using Blob remote storage...')
}

return {
Expand Down
5 changes: 3 additions & 2 deletions _nuxthub/server/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { drizzle as drizzleHTTP } from 'drizzle-orm/sqlite-proxy'
import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy'
import { ofetch } from 'ofetch'

export { sql } from 'drizzle-orm'

// TODO: generate #hub/database/schema from the database
export * as tables from '~/server/database/schema'

let _db: DrizzleD1Database | BetterSQLite3Database | SqliteRemoteDatabase
Expand All @@ -13,7 +16,6 @@ let _client: D1Database
export function useDatabase () {
if (!_db) {
if (import.meta.dev && process.env.NUXT_HUB_URL) {
console.log('Using D1 remote database...')
_db = drizzleHTTP(async (sql, params, method) => {
// https://orm.drizzle.team/docs/get-started-sqlite#http-proxy
try {
Expand All @@ -40,7 +42,6 @@ export function useDatabase () {
if (binding) {
_client = binding as D1Database
_db = drizzleD1(_client)
import.meta.dev && console.log('Using D1 local database...')
} else {
throw createError('Missing Cloudflare D1 binding DB')
}
Expand Down
1 change: 0 additions & 1 deletion _nuxthub/server/utils/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ let _kv: Storage
export function useKV () {
if (!_kv) {
if (import.meta.dev && process.env.NUXT_HUB_URL) {
console.log('Using KV remote namespace...')
// Use https://unstorage.unjs.io/drivers/http
_kv = createStorage({
driver: httpDriver({
Expand Down
2 changes: 0 additions & 2 deletions server/plugins/migrations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { sql } from 'drizzle-orm'

export default defineNitroPlugin(() => {
if (import.meta.dev) {
onHubReady(async () => {
Expand Down

0 comments on commit 77e6800

Please sign in to comment.