seahaven-site/terraform/functions/directory-index.js
Adam Moussa 758327f0c6
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.
2026-09-24 17:20:51 -04:00

42 lines
1.2 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;
if (RETIRED_JOB_URIS[uri]) {
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;
}