Package io.jmix.flowui.devserver
Class AbstractDevServerRunner
java.lang.Object
io.jmix.flowui.devserver.AbstractDevServerRunner
- All Implemented Interfaces:
com.vaadin.flow.internal.DevModeHandler,com.vaadin.flow.server.RequestHandler,Serializable
- Direct Known Subclasses:
ViteHandler
public abstract class AbstractDevServerRunner
extends Object
implements com.vaadin.flow.internal.DevModeHandler
Deals with most details of starting a frontend development server or
connecting to an existing one.
This class is meant to be used during developing time.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDevServerRunner(com.vaadin.flow.di.Lookup lookup, int runningPort, File npmFolder, File studioFolder, CompletableFuture<Void> waitFor) Craete an instance that waits for the given task to complete before starting or connecting to the server. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanCheck the connection to the dev server.protected ProcessStarts the dev server and returns the started process.protected com.vaadin.flow.server.startup.ApplicationConfigurationGets the application configuration.intgetPort()Get the listening port of the dev server.protected abstract FileGets the binary that starts the dev server.protected abstract FileGets the main configuration file for the dev server.protected abstract PatternGets a pattern to match with the output to determine that the server has failed to start.protected abstract StringGets the name of the dev server for outputting to the user and statistics.protected PatternGets a pattern to match with the output to determine that the server has been restarted.protected PatternGets a pattern to match with the output to determine that the server is restarting.Gets the commands to run to start the dev server.protected abstract PatternGets a pattern to match with the output to determine that the server has started successfully.protected io.jmix.flowui.devserver.DevServerWatchDogGets the server watch dog.booleanhandleRequest(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request, com.vaadin.flow.server.VaadinResponse response) protected voidCalled whenever the dev server output matched the success or failure pattern.prepareConnection(String path, String method) booleanserveDevModeRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Serve a file by proxying to the dev server.voidstop()protected voidTriggers live reload.protected voidupdateServerStartupEnvironment(FrontendTools frontendTools, Map<String, String> environment) Defines the environment variables to use when starting the dev server.protected voidValidates that the needed server binary and config file(s) are available.voidWaits for the dev server to start.protected voidwriteStream(jakarta.servlet.ServletOutputStream outputStream, InputStream inputStream)
-
Field Details
-
DEV_SERVER_HOST
- See Also:
-
-
Constructor Details
-
AbstractDevServerRunner
protected AbstractDevServerRunner(com.vaadin.flow.di.Lookup lookup, int runningPort, File npmFolder, File studioFolder, CompletableFuture<Void> waitFor) Craete an instance that waits for the given task to complete before starting or connecting to the server.- Parameters:
lookup- a lookup instancerunningPort- the port that a dev server is already running on or 0 to start a new servernpmFolder- folder with npm configuration filesstudioFolder- folder with generated fileswaitFor- the task to wait for before running the server.
-
-
Method Details
-
validateFiles
protected void validateFiles() throws com.vaadin.flow.server.ExecutionFailedExceptionValidates that the needed server binary and config file(s) are available.- Throws:
com.vaadin.flow.server.ExecutionFailedException- if there is a problem
-
getServerBinary
Gets the binary that starts the dev server. -
getServerConfig
Gets the main configuration file for the dev server. -
getServerName
Gets the name of the dev server for outputting to the user and statistics. -
getServerStartupCommand
Gets the commands to run to start the dev server.- Parameters:
tools- the frontend tools object
-
updateServerStartupEnvironment
protected void updateServerStartupEnvironment(FrontendTools frontendTools, Map<String, String> environment) Defines the environment variables to use when starting the dev server.- Parameters:
frontendTools- frontend tools metadataenvironment- the environment variables to use
-
getServerSuccessPattern
Gets a pattern to match with the output to determine that the server has started successfully. -
getServerFailurePattern
Gets a pattern to match with the output to determine that the server has failed to start. -
getServerRestartingPattern
Gets a pattern to match with the output to determine that the server is restarting. Defaults to null, meaning that server restart is not monitored. Server restart is monitored only if both this method andgetServerRestartedPattern()provides a pattern. -
getServerRestartedPattern
Gets a pattern to match with the output to determine that the server has been restarted. Defaults to null, meaning that server restart is not monitored. Server restart is monitored only if both this method andgetServerRestartingPattern()provides a pattern. -
doStartDevServer
Starts the dev server and returns the started process.- Returns:
- the started process or
nullif no process was started
-
onDevServerCompilation
Called whenever the dev server output matched the success or failure pattern. -
getFailedOutput
- Specified by:
getFailedOutputin interfacecom.vaadin.flow.internal.DevModeHandler
-
getWatchDog
protected io.jmix.flowui.devserver.DevServerWatchDog getWatchDog()Gets the server watch dog.- Returns:
- the watch dog
-
triggerLiveReload
protected void triggerLiveReload()Triggers live reload. -
getProjectRoot
- Specified by:
getProjectRootin interfacecom.vaadin.flow.internal.DevModeHandler
-
getStudioRoot
-
getApplicationConfiguration
protected com.vaadin.flow.server.startup.ApplicationConfiguration getApplicationConfiguration()Gets the application configuration.- Returns:
- the application configuration
-
checkConnection
protected boolean checkConnection()Check the connection to the dev server.- Returns:
trueif the dev server is responding correctly,falseotherwise
-
getPort
public int getPort()Get the listening port of the dev server.- Specified by:
getPortin interfacecom.vaadin.flow.internal.DevModeHandler- Returns:
- the listening port
-
waitForDevServer
public void waitForDevServer()Waits for the dev server to start.Suspends the caller's thread until the dev mode server is started (or failed to start).
-
stop
public void stop()- Specified by:
stopin interfacecom.vaadin.flow.internal.DevModeHandler
-
prepareConnection
- Specified by:
prepareConnectionin interfacecom.vaadin.flow.internal.DevModeHandler- Throws:
IOException
-
handleRequest
public boolean handleRequest(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request, com.vaadin.flow.server.VaadinResponse response) throws IOException - Specified by:
handleRequestin interfacecom.vaadin.flow.server.RequestHandler- Throws:
IOException
-
serveDevModeRequest
public boolean serveDevModeRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException Serve a file by proxying to the dev server.Note: it considers the
HttpServletRequest.getPathInfo()that will be the path passed to the dev server which is running in the context root folder of the application.Method returns
falseimmediately if dev server failed on its startup.- Specified by:
serveDevModeRequestin interfacecom.vaadin.flow.internal.DevModeHandler- Parameters:
request- the servlet requestresponse- the servlet response- Returns:
- false if the dev server returned a not found, true otherwise
- Throws:
IOException- in the case something went wrong like connection refused
-
writeStream
protected void writeStream(jakarta.servlet.ServletOutputStream outputStream, InputStream inputStream) throws IOException - Throws:
IOException
-