Skip to content

Commit bfcb270

Browse files
committed
feat: add validation to ensure target is a domain and not a URL
1 parent fd1c671 commit bfcb270

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
102102
return
103103
}
104104

105+
if (target.match(/^(?:https?)?:\/\//)) {
106+
consola.fail('target must be a domain')
107+
return
108+
}
109+
105110
const _printUrls = server.printUrls.bind(server)
106111

107112
let source = `localhost:${config.server.port || 5173}`
@@ -138,6 +143,11 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
138143
return
139144
}
140145

146+
if (target.match(/^(?:https?)?:\/\//)) {
147+
consola.fail('target must be a domain')
148+
return
149+
}
150+
141151
const devServer = {
142152
host: 'localhost',
143153
port: 8080,
@@ -200,6 +210,11 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
200210
return
201211
}
202212

213+
if (target.match(/^(?:https?)?:\/\//)) {
214+
consola.fail('target must be a domain')
215+
return
216+
}
217+
203218
const devServer = {
204219
host: 'localhost',
205220
port: 8080,

src/nuxt.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export default defineNuxtModule<ModuleOptions>({
3636
return
3737
}
3838

39+
if (target.match(/^(?:https?)?:\/\//)) {
40+
consola.fail('target must be a domain')
41+
return
42+
}
43+
3944
// https://github.com/nuxt/cli/issues/220#issuecomment-1735394141
4045
_nuxt.hook('listen', (_, listener) => {
4146
const url = listener.url

0 commit comments

Comments
 (0)