Skip to content

Commit

Permalink
fix: allow empty ignoredHostnames to remove localhost (fixes #30)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Aug 3, 2024
1 parent 34d9e4b commit e592b98
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from '@nuxt/kit'
import { name, version } from '../package.json'

const DEFAULT_HOSTNAMES = ['localhost']

export interface ModuleOptions {
/**
* Whether the tracker shall be enabled.
Expand Down Expand Up @@ -103,7 +105,7 @@ export default defineNuxtModule<ModuleOptions>({
enabled: true,
hashMode: false,
domain: '',
ignoredHostnames: ['localhost'],
ignoredHostnames: [],
ignoreSubDomains: false,
trackLocalhost: false,
apiHost: 'https://plausible.io',
Expand All @@ -118,11 +120,14 @@ export default defineNuxtModule<ModuleOptions>({
// Dedupe `ignoredHostnames` items
options.ignoredHostnames = Array.from(new Set(options.ignoredHostnames))

// Add default hostnames if `ignoredHostnames` is empty
if (options.ignoredHostnames.length === 0) {
options.ignoredHostnames = DEFAULT_HOSTNAMES
}

// Migrate `trackLocalhost` to `ignoredHostnames`
if (options.trackLocalhost) {
logger.warn(
'The `trackLocalhost` option has been deprecated. Please use `ignoredHostnames` instead.',
)
logger.warn('The `trackLocalhost` option has been deprecated. Please use `ignoredHostnames` instead.')
options.ignoredHostnames = options.ignoredHostnames.filter(
domain => domain !== 'localhost',
)
Expand Down

0 comments on commit e592b98

Please sign in to comment.