seahaven-site/terraform/functions/directory-index.js
Adam Moussa f194d65ee5
Some checks failed
Deploy / deploy (push) Has been cancelled
fix(careers): return 301s for retired job URLs (DEV-297) (#68)
* fix(careers): return 301s for retired job URLs

Send the old careers paths to the Paychex portal from the viewer-request function so clients get a permanent redirect instead of the HTML stub.

* fix(careers): match retired job redirects case-insensitively

CloudFront does not normalize URI case, so a mixed-case old job link skipped the 301 and missed the lowercase S3 stub.
2026-09-24 21:31:30 +00:00

43 lines
1.3 KiB
JavaScript

var PORTAL_URL = "https://jobs.appone.com/seahaven";
// Retired local job pages. Redirect before the directory-index rewrite so
// these paths never fall through to the HTML stubs in S3.
var RETIRED_JOB_URIS = {
"/careers/dispatcher": 1,
"/careers/dispatcher/": 1,
"/careers/dispatcher/index.html": 1,
"/careers/scheduling-coordinator": 1,
"/careers/scheduling-coordinator/": 1,
"/careers/scheduling-coordinator/index.html": 1,
"/careers/traveling-maintenance-assistant": 1,
"/careers/traveling-maintenance-assistant/": 1,
"/careers/traveling-maintenance-assistant/index.html": 1
};
function handler(event) {
var request = event.request;
var uri = request.uri;
// CloudFront does not normalize URI case. The S3 keys are lowercase.
if (RETIRED_JOB_URIS[uri.toLowerCase()]) {
return {
statusCode: 301,
statusDescription: "Moved Permanently",
headers: {
location: { value: PORTAL_URL }
}
};
}
var last = uri.substring(uri.lastIndexOf("/") + 1);
// S3 OAC has no directory index. default_root_object only covers "/".
// Keep the browser URL; rewrite the origin key to …/index.html.
if (uri.endsWith("/")) {
request.uri = uri + "index.html";
} else if (last.length > 0 && last.indexOf(".") === -1) {
request.uri = uri + "/index.html";
}
return request;
}