(request: Request)
| 5 | * @returns Current domain |
| 6 | */ |
| 7 | export const createDomain = (request: Request) => { |
| 8 | const headers = request.headers |
| 9 | const maybeProto = headers.get("x-forwarded-proto") |
| 10 | const maybeHost = headers.get("host") |
| 11 | const url = new URL(request.url) |
| 12 | // If the request is behind a proxy, we need to use the x-forwarded-proto and host headers |
| 13 | // to get the correct domain |
| 14 | if (maybeProto) { |
| 15 | return `${maybeProto}://${maybeHost ?? url.host}` |
| 16 | } |
| 17 | // If we are in local development, return the localhost |
| 18 | if (url.hostname === "localhost") { |
| 19 | return `http://${url.host}` |
| 20 | } |
| 21 | // If we are in production, return the production domain |
| 22 | return `https://${url.host}` |
| 23 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…