admin管理员组

文章数量:1279207

I have a cloudfront distribution that backs into and S3 bucket. There are custom error pages that direct 403/404 errors to "/notfound.html". The S3 bucket contains a directory per environment, and there is a cloudfront function that, amongst other things, directs the incoming request into the appropriate folder based on URL (host header):

async function handler( event ) {
  var request = event.request;

    // Backend redirection for dev/test.
    switch ( request.headers.host.value ) {
      case 'dev.mydomain':
        request.uri = '/dev' + request.uri;
        break;
      case 'test.mydomain':
        request.uri = '/test' + request.uri;
        break;
      default:
        request.uri = '/prod' + request.uri;
        break;
    }

    return request;
  }

The custom error page appears to bypass the cloudfront function and thus is served from the backend root rather than the environment specific folder. Anyone now of a workaround to this? I'd thought to return 302 with the error page config, but this isn't supported by cloudfront.

本文标签: