com.vaadin.flow.server.
Class DevModeHandler
- java.lang.Object
-
- com.vaadin.flow.server.DevModeHandler
-
All Implemented Interfaces:
public final class DevModeHandler extends Object implements RequestHandler
Handles getting resources from
webpack-dev-server
.This class is meant to be used during developing time. For a production mode site
webpack
generates the static bundles that will be served directly from the servlet (using a default servlet if such exists) or through a stand alone static file server. By default it keeps updated npm dependencies and node imports before running webpack serverFor internal use only. May be renamed or removed in a future release.
Since:
2.0
See Also:
-
-
Field Summary
Fields Modifier and Type Field and Description static String
WEBPACK_SERVER
The local installation path of the webpack-dev-server node script.
-
Method Summary
All Methods Modifier and Type Method and Description static DevModeHandler
getDevModeHandler()
Get the instantiated DevModeHandler.
String
getFailedOutput()
Return webpack console output when a compilation error happened.
BrowserLiveReload
getLiveReload()
Get the live reload service instance.
int
getPort()
Get the listening port of the 'webpack-dev-server'.
boolean
handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
Called when a request needs to be handled.
boolean
isDevModeRequest(HttpServletRequest request)
Returns true if it's a request that should be handled by webpack.
HttpURLConnection
prepareConnection(String path, String method)
Prepare a HTTP connection against webpack-dev-server.
void
removeRunningDevServerPort()
Remove the running port from the vaadinContext and temporary file.
boolean
reuseDevServer()
Whether the 'webpack-dev-server' should be reused on servlet reload.
boolean
serveDevModeRequest(HttpServletRequest request, HttpServletResponse response)
Serve a file by proxying to webpack.
void
setLiveReload(BrowserLiveReload liveReload)
Set the live reload service instance.
static DevModeHandler
start(DeploymentConfiguration configuration, File npmFolder, CompletableFuture<Void> waitFor)
Start the dev mode handler if none has been started yet.
static DevModeHandler
start(int runningPort, DeploymentConfiguration configuration, File npmFolder, CompletableFuture<Void> waitFor)
Start the dev mode handler if none has been started yet.
void
stop()
Stop the webpack-dev-server.
-
-
-
Field Detail
-
WEBPACK_SERVER
public static final String WEBPACK_SERVER
The local installation path of the webpack-dev-server node script.
See Also:
-
-
Method Detail
-
start
public static DevModeHandler start(DeploymentConfiguration configuration, File npmFolder, CompletableFuture<Void> waitFor)
Start the dev mode handler if none has been started yet.
Parameters:
configuration
- deployment configurationnpmFolder
- folder with npm configuration fileswaitFor
- a completable future whose execution result needs to be available to start the webpack dev serverReturns:
the instance in case everything is alright, null otherwise
-
start
public static DevModeHandler start(int runningPort, DeploymentConfiguration configuration, File npmFolder, CompletableFuture<Void> waitFor)
Start the dev mode handler if none has been started yet.
Parameters:
runningPort
- port on which Webpack is listening.configuration
- deployment configurationnpmFolder
- folder with npm configuration fileswaitFor
- a completable future whose execution result needs to be available to start the webpack dev serverReturns:
the instance in case everything is alright, null otherwise
-
getDevModeHandler
public static DevModeHandler getDevModeHandler()
Get the instantiated DevModeHandler.
Returns:
devModeHandler or
null
if not started
-
handleRequest
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
Description copied from interface:
RequestHandler
Called when a request needs to be handled. If a response is written, this method should return
true
to indicate that no more request handlers should be invoked for the request.Note that request handlers by default do not lock the session. If you are using VaadinSession or anything inside the VaadinSession you must ensure the session is locked. This can be done by extending
SynchronizedRequestHandler
or by usingVaadinSession.accessSynchronously(Command)
orUI.accessSynchronously(Command)
.Specified by:
handleRequest
in interfaceRequestHandler
Parameters:
session
- The session for the requestrequest
- The request to handleresponse
- The response object to which a response can be written.Returns:
true if a response has been written and no further request handlers should be called, otherwise false
Throws:
IOException
- If an IO error occurred
-
setLiveReload
public void setLiveReload(BrowserLiveReload liveReload)
Set the live reload service instance.
Parameters:
liveReload
- the live reload instance
-
getLiveReload
public BrowserLiveReload getLiveReload()
Get the live reload service instance.
Returns:
the live reload instance
-
isDevModeRequest
public boolean isDevModeRequest(HttpServletRequest request)
Returns true if it's a request that should be handled by webpack.
Parameters:
request
- the servlet requestReturns:
true if the request should be forwarded to webpack
-
serveDevModeRequest
public boolean serveDevModeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException
Serve a file by proxying to webpack.
Note: it considers the
HttpServletRequest#getPathInfo
that will be the path passed to the 'webpack-dev-server' which is running in the context root folder of the application.Method returns
false
immediately if dev server failed on its startup.Parameters:
request
- the servlet requestresponse
- the servlet responseReturns:
false if webpack returned a not found, true otherwise
Throws:
IOException
- in the case something went wrong like connection refused
-
prepareConnection
public HttpURLConnection prepareConnection(String path, String method) throws IOException
Prepare a HTTP connection against webpack-dev-server.
Parameters:
path
- the file to requestmethod
- the http method to useReturns:
the connection
Throws:
IOException
- on connection error
-
getFailedOutput
public String getFailedOutput()
Return webpack console output when a compilation error happened.
Returns:
console output if error or null otherwise.
-
removeRunningDevServerPort
public void removeRunningDevServerPort()
Remove the running port from the vaadinContext and temporary file.
-
getPort
public int getPort()
Get the listening port of the 'webpack-dev-server'.
Returns:
the listening port of webpack
-
reuseDevServer
public boolean reuseDevServer()
Whether the 'webpack-dev-server' should be reused on servlet reload. Default true.
Returns:
true in case of reusing the server.
-
stop
public void stop()
Stop the webpack-dev-server.
-
-