Fix domains with ports & localhost subdomains
This commit is contained in:
parent
8aa5675ba2
commit
c0dd29c591
@ -61,7 +61,9 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
current = domain
|
current = domain
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return current || host
|
// Setting the domain to localhost doesn't seem to work for subdomains (for
|
||||||
|
// example dev.localhost).
|
||||||
|
return current && current !== "localhost" ? current : host
|
||||||
}
|
}
|
||||||
|
|
||||||
public maybeProxyRequest(
|
public maybeProxyRequest(
|
||||||
@ -90,12 +92,11 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
// At minimum there needs to be sub.domain.tld.
|
// Split into parts.
|
||||||
const host = request.headers.host
|
const host = request.headers.host || ""
|
||||||
const parts = host && host.split(".")
|
const idx = host.indexOf(":")
|
||||||
if (!parts || parts.length < 3) {
|
const domain = idx !== -1 ? host.substring(0, idx) : host
|
||||||
return undefined
|
const parts = domain.split(".")
|
||||||
}
|
|
||||||
|
|
||||||
// There must be an exact match.
|
// There must be an exact match.
|
||||||
const port = parts.shift()
|
const port = parts.shift()
|
||||||
|
@ -581,6 +581,9 @@ export class HttpServer {
|
|||||||
this.heart.beat()
|
this.heart.beat()
|
||||||
const route = this.parseUrl(request)
|
const route = this.parseUrl(request)
|
||||||
const write = (payload: HttpResponse): void => {
|
const write = (payload: HttpResponse): void => {
|
||||||
|
const host = request.headers.host || ""
|
||||||
|
const idx = host.indexOf(":")
|
||||||
|
const domain = idx !== -1 ? host.substring(0, idx) : host
|
||||||
response.writeHead(payload.redirect ? HttpCode.Redirect : payload.code || HttpCode.Ok, {
|
response.writeHead(payload.redirect ? HttpCode.Redirect : payload.code || HttpCode.Ok, {
|
||||||
"Content-Type": payload.mime || getMediaMime(payload.filePath),
|
"Content-Type": payload.mime || getMediaMime(payload.filePath),
|
||||||
...(payload.redirect ? { Location: this.constructRedirect(request, route, payload as RedirectResponse) } : {}),
|
...(payload.redirect ? { Location: this.constructRedirect(request, route, payload as RedirectResponse) } : {}),
|
||||||
@ -591,9 +594,7 @@ export class HttpServer {
|
|||||||
"Set-Cookie": [
|
"Set-Cookie": [
|
||||||
`${payload.cookie.key}=${payload.cookie.value}`,
|
`${payload.cookie.key}=${payload.cookie.value}`,
|
||||||
`Path=${normalize(payload.cookie.path || "/", true)}`,
|
`Path=${normalize(payload.cookie.path || "/", true)}`,
|
||||||
request.headers.host
|
domain ? `Domain=${(this.proxy && this.proxy.getCookieDomain(domain)) || domain}` : undefined,
|
||||||
? `Domain=${(this.proxy && this.proxy.getCookieDomain(request.headers.host)) || request.headers.host}`
|
|
||||||
: undefined,
|
|
||||||
// "HttpOnly",
|
// "HttpOnly",
|
||||||
"SameSite=strict",
|
"SameSite=strict",
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user