Skip to content
Snippets Groups Projects
Select Git revision
  • ce68c9e03a884cc11cddc2f30f09f8a0e467c62c
  • master default protected
2 results

autoredirect.ts

Blame
  • autoredirect.ts 615 B
    import * as express from "express"
    import {debug} from "./debug";
    
    
    function AutoRedirect(req : express.Request, res : express.Response, next : express.NextFunction){
    
        //get last character of req string.
        let lastchar : string = req.path.substr(req.path.length-1, 1);
        debug(`Last character: '${lastchar}' : ${req.path}`);
    
        if(lastchar == '/'){
            res.redirect(req.path + "index.html");
            res.end();
        // }else if(req.path.lastIndexOf('.') < req.path.lastIndexOf('/')){
        //     res.redirect(req.path + ".html");
        //     res.end();
        }else
            next();
    }
    
    export {AutoRedirect};