|
1 | 1 | import type { ResolvedConfig as ResolvedViteConfig } from 'vite' |
2 | 2 | import type { Vitest } from '../core' |
| 3 | +import type { Logger } from '../logger' |
3 | 4 | import type { BenchmarkBuiltinReporters } from '../reporters' |
4 | 5 | import type { ResolvedBrowserOptions } from '../types/browser' |
5 | 6 | import type { |
@@ -55,10 +56,14 @@ function parseInspector(inspect: string | undefined | boolean | number) { |
55 | 56 | return { host, port: Number(port) || defaultInspectPort } |
56 | 57 | } |
57 | 58 |
|
| 59 | +/** |
| 60 | + * @deprecated Internal function |
| 61 | + */ |
58 | 62 | export function resolveApiServerConfig<Options extends ApiConfig & Omit<UserConfig, 'expect'>>( |
59 | 63 | options: Options, |
60 | 64 | defaultPort: number, |
61 | 65 | parentApi?: ApiConfig, |
| 66 | + logger?: Logger, |
62 | 67 | ): ApiConfig | undefined { |
63 | 68 | let api: ApiConfig | undefined |
64 | 69 |
|
@@ -100,6 +105,16 @@ export function resolveApiServerConfig<Options extends ApiConfig & Omit<UserConf |
100 | 105 |
|
101 | 106 | // if the API server is exposed to network, disable write operations by default |
102 | 107 | if (!api.middlewareMode && api.host && api.host !== 'localhost' && api.host !== '127.0.0.1') { |
| 108 | + // assigned to browser |
| 109 | + if (parentApi) { |
| 110 | + if (api.allowWrite == null && api.allowExec == null) { |
| 111 | + logger?.error( |
| 112 | + c.yellow( |
| 113 | + `${c.yellowBright(' WARNING ')} API server is exposed to network, disabling write and exec operations by default for security reasons. This can case some APIs to not work as expected. Set \`browser.api.allowExec\` manually to hide this warning. See https://vitest.dev/config/browser/api for more details.`, |
| 114 | + ), |
| 115 | + ) |
| 116 | + } |
| 117 | + } |
103 | 118 | api.allowWrite ??= parentApi?.allowWrite ?? false |
104 | 119 | api.allowExec ??= parentApi?.allowExec ?? false |
105 | 120 | } |
@@ -805,6 +820,7 @@ export function resolveConfig( |
805 | 820 | resolved.browser, |
806 | 821 | defaultBrowserPort, |
807 | 822 | resolved.api, |
| 823 | + logger, |
808 | 824 | ) || { |
809 | 825 | port: defaultBrowserPort, |
810 | 826 | } |
|
0 commit comments