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.
Porting some logic from our older AWS Lambda@Edge, where we redirect requests for robots.txt to environment specific versions.
using FAB RC9
This works perfectly when run locally with
fab servehowever on AWS we getFABs do not support relative urls other than /_assetsChanging the path to start with
/_assets/results in an empty 200 html response locally and Access Denied (assume is 404) on AWSThere is no physical
robots.txtfile 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.