function createRedirectDirectoryListener(req, res, path) {
  return function redirect() {
    if (hasTrailingSlash(path)) {
      return sendError(res, createError(404));
    }
    // get original URL
    const originalUrl = original(req);
    // append trailing slash
    originalUrl.path = null;
    originalUrl.pathname = collapseLeadingSlashes(originalUrl.pathname + "/");
    // reformat the URL
    const loc = encodeUrl(originalUrl.pathname);
    const doc = createHtmlDocument(
      "Redirecting",
      'Redirecting to <a href="' + escapeHtml(loc) + '">' + escapeHtml(loc) +
        "</a>",
    );
    // send redirect response
    res.status = 301;
    res.set("Content-Type", "text/html; charset=UTF-8");
    res.set("Content-Security-Policy", "default-src 'none'");
    res.set("X-Content-Type-Options", "nosniff");
    res.set("Location", loc);
    res.send(doc);
  };
}
/**
 * Create a directory listener that performs a redirect.
 * @private
 */
Create a directory listener that performs a redirect.
@private
Create a directory listener that performs a redirect . @private
function createRedirectDirectoryListener(req, res, path) {
  return function redirect() {
    if (hasTrailingSlash(path)) {
      return sendError(res, createError(404));
    }
    const originalUrl = original(req);
    originalUrl.path = null;
    originalUrl.pathname = collapseLeadingSlashes(originalUrl.pathname + "/");
    const loc = encodeUrl(originalUrl.pathname);
    const doc = createHtmlDocument(
      "Redirecting",
      'Redirecting to <a href="' + escapeHtml(loc) + '">' + escapeHtml(loc) +
        "</a>",
    );
    res.status = 301;
    res.set("Content-Type", "text/html; charset=UTF-8");
    res.set("Content-Security-Policy", "default-src 'none'");
    res.set("X-Content-Type-Options", "nosniff");
    res.set("Location", loc);
    res.send(doc);
  };
}
function createRedirectDirectoryListener ( req , res , path ) { return function redirect ( ) { if ( hasTrailingSlash ( path ) ) { return sendError ( res , createError ( 404 ) ) ; } const originalUrl = original ( req ) ; originalUrl . path = null ; originalUrl . pathname = collapseLeadingSlashes ( originalUrl . pathname + "/" ) ; const loc = encodeUrl ( originalUrl . pathname ) ; const doc = createHtmlDocument ( "Redirecting" , 'Redirecting to <a href="' + escapeHtml ( loc ) + '">' + escapeHtml ( loc ) + "</a>" , ) ; res . status = 301 ; res . set ( "Content-Type" , "text/html; charset=UTF-8" ) ; res . set ( "Content-Security-Policy" , "default-src 'none'" ) ; res . set ( "X-Content-Type-Options" , "nosniff" ) ; res . set ( "Location" , loc ) ; res . send ( doc ) ; } ; }
Create a directory listener that performs a redirect.
Create a directory listener that performs a redirect .
// get original URL // append trailing slash // reformat the URL // send redirect response