Skip to content

Commit

Permalink
docs: warn when server.origin ends with /
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Apr 21, 2022
1 parent 3a5332c commit dee4aee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Expand Up @@ -461,7 +461,7 @@ export async function resolveConfig(
)
: ''

const server = resolveServerOptions(resolvedRoot, config.server)
const server = resolveServerOptions(resolvedRoot, config.server, logger)

const optimizeDeps = config.optimizeDeps || {}

Expand Down
16 changes: 15 additions & 1 deletion packages/vite/src/node/server/index.ts
Expand Up @@ -56,6 +56,7 @@ import type { OptimizedDeps } from '../optimizer'
import { resolveHostname } from '../utils'
import { searchForWorkspaceRoot } from './searchRoot'
import { CLIENT_DIR } from '../constants'
import type { Logger } from '../logger'
import { printCommonServerUrls } from '../logger'
import { performance } from 'perf_hooks'
import { invalidatePackageData } from '../packages'
Expand Down Expand Up @@ -703,7 +704,8 @@ function resolvedAllowDir(root: string, dir: string): string {

export function resolveServerOptions(
root: string,
raw?: ServerOptions
raw: ServerOptions | undefined,
logger: Logger
): ResolvedServerOptions {
const server: ResolvedServerOptions = {
preTransformRequests: true,
Expand All @@ -729,6 +731,18 @@ export function resolveServerOptions(
allow: allowDirs,
deny
}

if (server.origin?.endsWith('/')) {
server.origin = server.origin.slice(0, -1)
logger.warn(
colors.yellow(
`${colors.bold('(!)')} server.origin should not end with "/". Using "${
server.origin
}" instead.`
)
)
}

return server
}

Expand Down

0 comments on commit dee4aee

Please sign in to comment.