Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use server auto-imports #1675

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion modules/tauri/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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({
meta: {
Expand Down Expand Up @@ -38,6 +38,14 @@ export default defineNuxtModule({
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') })

addPlugin(resolve('./runtime/logging.client'))
Expand Down
2 changes: 0 additions & 2 deletions server/api/[server]/clear.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { deleteApp } from '~~/server/shared'

export default defineEventHandler(async (event) => {
const { server } = getRouterParams(event)
const { key } = getQuery(event)
Expand Down
2 changes: 0 additions & 2 deletions server/api/[server]/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { stringifyQuery } from 'ufo'
import { createError, defineEventHandler, getRouterParams, readBody } from 'h3'
import { getApp, getRedirectURI } from '~/server/shared'

export default defineEventHandler(async (event) => {
let { server } = getRouterParams(event)
Expand Down
4 changes: 1 addition & 3 deletions server/api/[server]/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { stringifyQuery } from 'vue-router'
import { createError, defineEventHandler, getQuery, getRouterParams, sendRedirect } from 'h3'
import { getApp, getRedirectURI } from '~/server/shared'
import { stringifyQuery } from 'ufo'

export default defineEventHandler(async (event) => {
const { origin } = getQuery(event) as { origin: string }
Expand Down
3 changes: 0 additions & 3 deletions server/api/list-servers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { defineEventHandler } from 'h3'
import { listServers } from '~/server/shared'

let servers: string[]

export default defineEventHandler(async () => {
Expand Down
4 changes: 2 additions & 2 deletions server/shared.ts → server/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { stringifyQuery } from 'ufo'
import { $fetch } from 'ofetch'
import type { Storage } from 'unstorage'

import cached from './cache-driver'
import kv from './cloudflare-driver'
import cached from '../cache-driver'
import kv from '../cloudflare-driver'

// @ts-expect-error virtual import
import { env } from '#build-info'
Expand Down