Skip to content

Link relations have undefined:// as a the protocol when X-STAC-Endpoint or STAC_API_URL are not set #917

@philvarner

Description

@philvarner

The code to determine the endpoint prefix to use when constructing link relation hrefs is:

const determineEndpoint = (req) => {
  const xStacEndpoint = req.get('X-STAC-Endpoint')
  if (xStacEndpoint) return xStacEndpoint

  if (process.env['STAC_API_URL']) return process.env['STAC_API_URL']

  const rootPath = process.env['STAC_API_ROOTPATH'] || ''

  if (req.get('X-Forwarded-Proto') && req.get('X-Forwarded-Host')) {
    return `${req.get('X-Forwarded-Proto')}://${req.get('X-Forwarded-Host')}${rootPath}`
  }

  return req.event && req.event.requestContext && req.event.requestContext.stage
    ? `${req.get('X-Forwarded-Proto')}://${req.get('Host')}/${req.event.requestContext.stage}`
    : `${req.get('X-Forwarded-Proto')}://${req.get('Host')}${rootPath}`
}

In most cases, one of X-STAC-Endpoint (for proxys) or STAC_API_URL (when an explicit custom domain name is used) are set.

It seems that X-Forwarded-Proto and possibly X-Forwarded-Host are not set by the API Gateway REST API integration. I doubt this is a new behavior since AWS usually keeps things like that very consistent, so it may never have worked. In this particular case, X-Forwarded-Proto is undefined, so the urls come out starting with undefined://

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions