Skip to content

Commit

Permalink
feat(config): add configuration file options
Browse files Browse the repository at this point in the history
  • Loading branch information
radyakaze committed Oct 1, 2024
1 parent 4496c64 commit 0414482
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineNuxtModule, createResolver, addServerPlugin } from '@nuxt/kit'
import logger from './runtime/utils/logger'

export interface ModuleOptions {
//
configFile?: string
}

export default defineNuxtModule<ModuleOptions>({
Expand All @@ -14,12 +14,15 @@ export default defineNuxtModule<ModuleOptions>({
nuxt: '^3.0.0',
},
},
async setup(_options, nuxt) {
defaults: {
configFile: 'server.config',
},
async setup(options, nuxt) {
const resolver = createResolver(import.meta.url)

nuxt.options.alias['#nuxt-proxy-party'] = resolver.resolve('./core')

const serverConfigPath = await resolver.resolvePath('server.config', {
const serverConfigPath = await resolver.resolvePath(options.configFile ?? 'server.config', {
cwd: nuxt.options.rootDir,
extensions: ['.js', '.mjs', '.ts'],
})
Expand All @@ -33,7 +36,7 @@ export default defineNuxtModule<ModuleOptions>({
serverConfig = await readFile(serverConfigPath, 'utf8')
}
catch {
logger.warn('No server.config found')
logger.warn('No config found')
}

config.virtual['#nuxt-proxy-party-options'] = serverConfig
Expand Down

0 comments on commit 0414482

Please sign in to comment.