refactor: use server auto-imports (#1675)

This commit is contained in:
Daniel Roe 2023-02-08 12:00:43 -08:00 committed by GitHub
parent 7da49afde5
commit f04b09a40d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 13 deletions

View file

@ -1,5 +1,5 @@
import { rm } from 'fs/promises' import { rm } from 'fs/promises'
import { addImports, addPlugin, createResolver, defineNuxtModule, useNuxt } from '@nuxt/kit' import { addImports, addImportsSources, addPlugin, createResolver, defineNuxtModule, useNuxt } from '@nuxt/kit'
export default defineNuxtModule({ export default defineNuxtModule({
meta: { meta: {
@ -38,6 +38,14 @@ export default defineNuxtModule({
config.scanDirs = [] config.scanDirs = []
}) })
addImportsSources({
from: 'h3',
imports: ['defineEventHandler', 'getQuery', 'getRouterParams', 'readBody', 'sendRedirect'] as Array<keyof typeof import('h3')>,
})
nuxt.options.imports.dirs = nuxt.options.imports.dirs || []
nuxt.options.imports.dirs.push(resolve('../../server/utils'))
addImports({ name: 'useStorage', from: resolve('./runtime/storage') }) addImports({ name: 'useStorage', from: resolve('./runtime/storage') })
addPlugin(resolve('./runtime/logging.client')) addPlugin(resolve('./runtime/logging.client'))

View file

@ -1,5 +1,3 @@
import { deleteApp } from '~~/server/shared'
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
const { server } = getRouterParams(event) const { server } = getRouterParams(event)
const { key } = getQuery(event) const { key } = getQuery(event)

View file

@ -1,6 +1,4 @@
import { stringifyQuery } from 'ufo' import { stringifyQuery } from 'ufo'
import { createError, defineEventHandler, getRouterParams, readBody } from 'h3'
import { getApp, getRedirectURI } from '~/server/shared'
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
let { server } = getRouterParams(event) let { server } = getRouterParams(event)

View file

@ -1,6 +1,4 @@
import { stringifyQuery } from 'vue-router' import { stringifyQuery } from 'ufo'
import { createError, defineEventHandler, getQuery, getRouterParams, sendRedirect } from 'h3'
import { getApp, getRedirectURI } from '~/server/shared'
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
const { origin } = getQuery(event) as { origin: string } const { origin } = getQuery(event) as { origin: string }

View file

@ -1,6 +1,3 @@
import { defineEventHandler } from 'h3'
import { listServers } from '~/server/shared'
let servers: string[] let servers: string[]
export default defineEventHandler(async () => { export default defineEventHandler(async () => {

View file

@ -8,8 +8,8 @@ import { stringifyQuery } from 'ufo'
import { $fetch } from 'ofetch' import { $fetch } from 'ofetch'
import type { Storage } from 'unstorage' import type { Storage } from 'unstorage'
import cached from './cache-driver' import cached from '../cache-driver'
import kv from './cloudflare-driver' import kv from '../cloudflare-driver'
// @ts-expect-error virtual import // @ts-expect-error virtual import
import { env } from '#build-info' import { env } from '#build-info'