Class Redirector

java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.Service
services.moleculer.web.middleware.HttpMiddleware
services.moleculer.web.middleware.Redirector
All Implemented Interfaces:
services.moleculer.service.MoleculerLifecycle, HttpConstants

public class Redirector extends HttpMiddleware implements HttpConstants
Redirects all requests to the specified URL / location. Sample:
// This middleware redirects "/" path to "index.html"
route.use(new Redirector("/", "index.html", 307));
  • Field Details

    • status

      protected int status
      307 = Temporary Redirect.
    • path

      protected String path
      Path to redirect (null = redirects all requests).
    • formattedPath

      protected String formattedPath
      Path to redirect (formatted and checked).
    • location

      protected String location
      URL of the redirection.
    • htmlTemplate

      protected String htmlTemplate
      Template of the HTML response.
  • Constructor Details

    • Redirector

      public Redirector()
    • Redirector

      public Redirector(String path)
      Redirects browser from "path" to "index.html".
      Parameters:
      path - redirect FROM (eg. "/deleted-page.html")
    • Redirector

      public Redirector(String path, String location)
      Redirects browser from "path" to "location" URI.
      Parameters:
      path - redirect FROM (eg. "/deleted-page.html")
      location - redirect TO (eg. "new-page.html")
    • Redirector

      public Redirector(String path, String location, int status)
      Redirects browser from "path" to "location" URI.
      Parameters:
      path - redirect FROM (eg. "/deleted-page.html")
      location - redirect TO (eg. "new-page.html")
      status - status code (eg. 307 = Temporary Redirect)
  • Method Details

    • install

      public RequestProcessor install(RequestProcessor next, io.datatree.Tree config)
      Specified by:
      install in class HttpMiddleware
    • getHtmlTemplate

      public String getHtmlTemplate()
      Returns:
      the htmlTemplate
    • setHtmlTemplate

      public void setHtmlTemplate(String htmlTemplate)
      Parameters:
      htmlTemplate - the htmlTemplate to set
    • getLocation

      public String getLocation()
      Returns:
      the location
    • setLocation

      public void setLocation(String location)
      Parameters:
      location - the location to set
    • getStatus

      public int getStatus()
      Returns:
      the status
    • setStatus

      public void setStatus(int status)
      Parameters:
      status - the status to set
    • getPath

      public String getPath()
      Returns:
      the path
    • setPath

      public void setPath(String path)
      Parameters:
      path - the path to set