Skip to content

Commit 2986210

Browse files
committed
feat: add logs when no proxy configured #68
1 parent 4f8d330 commit 2986210

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/mockMiddleware.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { Server } from 'node:http'
22
import type { Http2SecureServer } from 'node:http2'
3-
import { isBoolean, toArray } from '@pengzhanbo/utils'
3+
import { isBoolean, toArray, uniq } from '@pengzhanbo/utils'
44
import cors, { type CorsOptions } from 'cors'
55
import { pathToRegexp } from 'path-to-regexp'
66
import type { Connect, ResolvedConfig, WebSocketServer } from 'vite'
7+
import c from 'picocolors'
78
import { baseMiddleware } from './baseMiddleware'
89
import { viteDefine } from './define'
910
import { createLogger } from './logger'
@@ -60,7 +61,11 @@ export function mockServerMiddleware(
6061
* 但在大多数场景下,共用 `server.proxy` 已足够
6162
*/
6263
const prefix = toArray(options.prefix)
63-
const proxies = [...prefix, ...httpProxies]
64+
const proxies = uniq([...prefix, ...httpProxies])
65+
66+
// #68
67+
if (!proxies.length)
68+
logger.warn(`No proxy was configured, mock server will not work. See ${c.cyan('https://vite-plugin-mock-dev-server.netlify.app/guide/usage')}`)
6469

6570
/**
6671
* 虽然 config.server.proxy 中有关于 ws 的代理配置,

0 commit comments

Comments
 (0)