Skip to content

Difference in behaviour locally vs AWS for server side relative redirects to public files #349

@thejuan

Description

@thejuan

Porting some logic from our older AWS Lambda@Edge, where we redirect requests for robots.txt to environment specific versions.

using FAB RC9

import { FABRuntime } from "@fab/core";
import { getEnvironment } from "@hatch-team/ui-config";

export default function robotsRedirect({ Router }: FABRuntime) {
  Router.on("/robots.txt", async ({ request }) => {
    const newUrl = `/robots.${getEnvironment().getName()}.txt`;
    console.log(`Redirecting robots.txt to ${newUrl}`);
    return new Request(newUrl, request.clone());
  });
}

This works perfectly when run locally with fab serve however on AWS we get FABs do not support relative urls other than /_assets

Changing the path to start with /_assets/ results in an empty 200 html response locally and Access Denied (assume is 404) on AWS

There is no physical robots.txt file but this doesn't seem to change the error when added.

The code seems to match the concepts in the docs around dog and cat origin request transformations.
I'll just make the code use an absolute URL for now.

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