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
Redirects all requests to the specified URL / location. Sample:
// This middleware redirects "/" path to "index.html"
route.use(new Redirector("/", "index.html", 307));
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringPath to redirect (formatted and checked).protected StringTemplate of the HTML response.protected StringURL of the redirection.protected StringPath to redirect (null = redirects all requests).protected int307 = Temporary Redirect.Fields inherited from class services.moleculer.service.MoleculerComponent
broker, logger, nameFields inherited from interface HttpConstants
ACCEPT, ACCEPT_ENCODING, AUTHORIZATION, CACHE_CONTROL, CHUNKED, CLOSE, CONNECT, CONNECTION, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE, CONTENT_TYPE_HTML, CONTENT_TYPE_JSON, COOKIE, DEFLATE, DELETE, ETAG, GET, GZIP, HEAD, IF_NONE_MATCH, KEEP_ALIVE, LOCATION, META_CONTENT_TYPE, META_HEADERS, META_LOCALE, META_LOCATION, META_SESSION, META_STATUS, META_TEMPLATE, NO_CACHE, OPTIONS, PATCH, POST, PROPERTY_COOKIES, PROPERTY_SESSION_ID, PROPERTY_USER, PUT, SET_COOKIE, TRACE, TRANSFER_ENCODING, WWW_AUTHENTICATE, X_FORWARDED_FOR -
Constructor Summary
ConstructorsConstructorDescriptionRedirector(String path) Redirects browser from "path" to "index.html".Redirector(String path, String location) Redirects browser from "path" to "location" URI.Redirector(String path, String location, int status) Redirects browser from "path" to "location" URI. -
Method Summary
Modifier and TypeMethodDescriptiongetPath()intinstall(RequestProcessor next, io.datatree.Tree config) voidsetHtmlTemplate(String htmlTemplate) voidsetLocation(String location) voidvoidsetStatus(int status) Methods inherited from class services.moleculer.service.MoleculerComponent
getBroker, getLogger, getName, started, stopped
-
Field Details
-
status
protected int status307 = Temporary Redirect. -
path
Path to redirect (null = redirects all requests). -
formattedPath
Path to redirect (formatted and checked). -
location
URL of the redirection. -
htmlTemplate
Template of the HTML response.
-
-
Constructor Details
-
Redirector
public Redirector() -
Redirector
Redirects browser from "path" to "index.html".- Parameters:
path- redirect FROM (eg. "/deleted-page.html")
-
Redirector
-
Redirector
-
-
Method Details
-
install
- Specified by:
installin classHttpMiddleware
-
getHtmlTemplate
- Returns:
- the htmlTemplate
-
setHtmlTemplate
- Parameters:
htmlTemplate- the htmlTemplate to set
-
getLocation
- Returns:
- the location
-
setLocation
- 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
- Returns:
- the path
-
setPath
- Parameters:
path- the path to set
-