public final class DevModeHandlerImpl extends Object implements RequestHandler, DevModeHandler
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 server
For internal use only. May be renamed or removed in a future release.
Modifier and Type | Field and Description |
---|---|
static String |
WEBPACK_SERVER
The local installation path of the webpack-dev-server node script.
|
Modifier and Type | Method and Description |
---|---|
static DevModeHandlerImpl |
getDevModeHandler()
Get the instantiated DevModeHandler.
|
String |
getFailedOutput()
Return webpack console output when a compilation error happened.
|
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(javax.servlet.http.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 |
serveDevModeRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Serve a file by proxying to webpack.
|
static DevModeHandlerImpl |
start(int runningPort,
Lookup lookup,
File npmFolder,
CompletableFuture<Void> waitFor)
Start the dev mode handler if none has been started yet.
|
static DevModeHandlerImpl |
start(Lookup lookup,
File npmFolder,
CompletableFuture<Void> waitFor)
Start the dev mode handler if none has been started yet.
|
void |
stop()
Stop the dev-server.
|
public static final String WEBPACK_SERVER
public static DevModeHandlerImpl start(Lookup lookup, File npmFolder, CompletableFuture<Void> waitFor)
lookup
- the provided lookup to get required datanpmFolder
- folder with npm configuration fileswaitFor
- a completable future whose execution result needs to be
available to start the webpack dev serverpublic static DevModeHandlerImpl start(int runningPort, Lookup lookup, File npmFolder, CompletableFuture<Void> waitFor)
runningPort
- port on which Webpack is listening.lookup
- the provided lookup to get required datanpmFolder
- folder with npm configuration fileswaitFor
- a completable future whose execution result needs to be
available to start the webpack dev serverpublic static DevModeHandlerImpl getDevModeHandler()
null
if not startedpublic boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
RequestHandler
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 using
VaadinSession.accessSynchronously(Command)
or
UI.accessSynchronously(Command)
.
handleRequest
in interface RequestHandler
session
- The session for the requestrequest
- The request to handleresponse
- The response object to which a response can be written.IOException
- If an IO error occurredpublic boolean isDevModeRequest(javax.servlet.http.HttpServletRequest request)
DevModeHandler
isDevModeRequest
in interface DevModeHandler
request
- the servlet requestpublic boolean serveDevModeRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
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.
serveDevModeRequest
in interface DevModeHandler
request
- the servlet requestresponse
- the servlet responseIOException
- in the case something went wrong like connection refusedpublic HttpURLConnection prepareConnection(String path, String method) throws IOException
DevModeHandler
prepareConnection
in interface DevModeHandler
path
- the file to request, needs to be safemethod
- the http method to useIOException
- on connection errorpublic String getFailedOutput()
DevModeHandler
getFailedOutput
in interface DevModeHandler
public void removeRunningDevServerPort()
public int getPort()
public void stop()
DevModeHandler
stop
in interface DevModeHandler
Copyright © 2021. All rights reserved.