@dwp/govuk-casa
Version:
A framework for building GOVUK Collect-And-Submit-Applications
28 lines • 939 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_js_1 = require("../lib/utils.js");
/**
* @typedef {import("express").RequestHandler} ExpressRequestHandler
* @access private
*/
/**
* @typedef {import("../casa").Plan} Plan
* @access private
*/
/**
* Redirect the user to the first Plan waypoint when they request the root /
* path.
*
* @param {Plan} plan CASA Plan
* @returns {ExpressRequestHandler[]} Array of middleware
*/
exports.default = ({ plan }) => [
(req, res) => {
const reqUrl = new URL(req.url, "https://placeholder.test/");
const reqPath = (0, utils_js_1.validateUrlPath)(`${req.baseUrl}${reqUrl.pathname}${plan.getWaypoints()[0]}`);
let reqParams = reqUrl.searchParams.toString();
reqParams = reqParams ? `?${reqParams}` : "";
res.redirect(302, `${reqPath}${reqParams}`);
},
];
//# sourceMappingURL=serve-first-waypoint.js.map