MCPcopy Create free account
hub / github.com/langgenius/dify / buildUpstreamUrl

Function buildUpstreamUrl

packages/dev-proxy/src/server.ts:81–94  ·  view source on GitHub ↗
(target: string, requestPath: string, search = '')

Source from the content-addressed store, hash-verified

79}
80
81export const buildUpstreamUrl = (target: string, requestPath: string, search = '') => {
82 const targetUrl = new URL(target)
83 const normalizedTargetPath = targetUrl.pathname === '/' ? '' : targetUrl.pathname.replace(/\/$/, '')
84 const normalizedRequestPath = requestPath.startsWith('/') ? requestPath : `/${requestPath}`
85 const hasTargetPrefix = normalizedTargetPath
86 && (normalizedRequestPath === normalizedTargetPath || normalizedRequestPath.startsWith(`${normalizedTargetPath}/`))
87
88 targetUrl.pathname = hasTargetPrefix
89 ? normalizedRequestPath
90 : `${normalizedTargetPath}${normalizedRequestPath}`
91 targetUrl.search = search
92
93 return targetUrl
94}
95
96const createProxyRequestHeaders = (
97 request: Request,

Callers 2

server.spec.tsFile · 0.90
proxyRequestFunction · 0.85

Calls 2

replaceMethod · 0.45
startsWithMethod · 0.45

Tested by

no test coverage detected