Class ServeStatic
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.Service
services.moleculer.web.middleware.HttpMiddleware
services.moleculer.web.middleware.ServeStatic
- All Implemented Interfaces:
services.moleculer.service.MoleculerLifecycle, HttpConstants
Service to serve files from within a given root directory. When a file is not
found, instead of sending a 404 response. Supports content compression,
automatic "Content-Type" detection, and ETAGs. Sample:
ServeStatic staticHandler = new ServeStatic("/", "/www");
staticHandler.setEnableReloading(true) // During the development
route.use(staticHandler);
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longDo not reload cache until...protected intCompress key and/or value above this size (BYTES), 0 = disable compressionprotected intCompression level (best speed = 1, best compression = 9).protected booleanEnables content reloading (in production mode set it to "false" for the better performance)protected io.datatree.dom.Cache<String, ServeStatic.CachedFile> protected StringFormatted local directory prefix (eg.protected StringLocal directory prefix (eg.protected intEnable caching for smaller files only (BYTES)protected intMaximum number of cached filesprotected longTime between each packet sent.protected intSize of packets.protected StringURL prefix (eg.protected booleanUse ETag headersFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongintintgetContentType(String extension) intintlongintinstall(RequestProcessor next, io.datatree.Tree config) booleanbooleanvoidsetCacheDelay(long cacheDelay) voidsetCompressAbove(int compressAbove) voidsetCompressionLevel(int compressionLevel) voidsetContentType(String extension, String contentType) voidsetEnableReloading(boolean enableReloading) voidsetLocalDirectory(String localDirectory) voidsetMaxCachedFileSize(int maxCachedFileSize) voidsetNumberOfCachedFiles(int numberOfCachedFiles) voidsetPacketDelay(long packetDelay) voidsetPacketSize(int packetSize) voidsetUseETags(boolean useETags) voidstarted(services.moleculer.ServiceBroker broker) voidstopped()Methods inherited from class services.moleculer.service.MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
defaultContentTypes
-
path
URL prefix (eg. "/files" or "/static") -
localDirectory
Local directory prefix (eg. "C:\content" or "www" or "WEB-INF\static") -
formattedLocalDirectory
Formatted local directory prefix (eg. "C:/content" or "/www" or "/WEB-INF/static") -
enableReloading
protected boolean enableReloadingEnables content reloading (in production mode set it to "false" for the better performance) -
numberOfCachedFiles
protected int numberOfCachedFilesMaximum number of cached files -
cacheDelay
protected long cacheDelayDo not reload cache until... (MILLISECONDS) -
maxCachedFileSize
protected int maxCachedFileSizeEnable caching for smaller files only (BYTES) -
useETags
protected boolean useETagsUse ETag headers -
compressAbove
protected int compressAboveCompress key and/or value above this size (BYTES), 0 = disable compression -
compressionLevel
protected int compressionLevelCompression level (best speed = 1, best compression = 9). -
packetSize
protected int packetSizeSize of packets. -
packetDelay
protected long packetDelayTime between each packet sent. This may be necessary because the other Threads will get some CPU-time. -
contentTypes
-
fileCache
-
-
Constructor Details
-
ServeStatic
public ServeStatic() -
ServeStatic
-
ServeStatic
-
-
Method Details
-
started
-
install
- Specified by:
installin classHttpMiddleware
-
stopped
public void stopped()- Specified by:
stoppedin interfaceservices.moleculer.service.MoleculerLifecycle- Overrides:
stoppedin classservices.moleculer.service.MoleculerComponent
-
getPacketSize
public int getPacketSize() -
setPacketSize
public void setPacketSize(int packetSize) -
getPacketDelay
public long getPacketDelay() -
setPacketDelay
public void setPacketDelay(long packetDelay) -
getLocalDirectory
-
setLocalDirectory
-
setContentType
-
getContentType
-
getNumberOfCachedFiles
public int getNumberOfCachedFiles() -
setNumberOfCachedFiles
public void setNumberOfCachedFiles(int numberOfCachedFiles) -
isEnableReloading
public boolean isEnableReloading() -
setEnableReloading
public void setEnableReloading(boolean enableReloading) -
getCacheDelay
public long getCacheDelay() -
setCacheDelay
public void setCacheDelay(long cacheDelay) -
getMaxCachedFileSize
public int getMaxCachedFileSize() -
setMaxCachedFileSize
public void setMaxCachedFileSize(int maxCachedFileSize) -
getCompressAbove
public int getCompressAbove() -
setCompressAbove
public void setCompressAbove(int compressAbove) -
isUseETags
public boolean isUseETags() -
setUseETags
public void setUseETags(boolean useETags) -
getCompressionLevel
public int getCompressionLevel() -
setCompressionLevel
public void setCompressionLevel(int compressionLevel)
-