mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Initial refactoring to abstract baseclass to allow for additional functionality across all routers
This commit is contained in:
@ -76,9 +76,9 @@ public class QApplicationJavalinServer
|
||||
private boolean serveFrontendMaterialDashboard = true;
|
||||
private String frontendMaterialDashboardHostedPath = "/"; // TODO - Things like this should be moved into a central configuration file system, so that it can be changed in userspace without code changes.
|
||||
private boolean serveLegacyUnversionedMiddlewareAPI = true;
|
||||
private List<AbstractMiddlewareVersion> middlewareVersionList = List.of(new MiddlewareVersionV1());
|
||||
private List<QJavalinRouteProviderInterface> additionalRouteProviders = null;
|
||||
private Consumer<Javalin> javalinConfigurationCustomizer = null;
|
||||
private List<AbstractMiddlewareVersion> middlewareVersionList = List.of(new MiddlewareVersionV1());
|
||||
private List<QJavalinRouteProvider> additionalRouteProviders = null;
|
||||
private Consumer<Javalin> javalinConfigurationCustomizer = null;
|
||||
private QJavalinMetaData javalinMetaData = null;
|
||||
|
||||
private long lastQInstanceHotSwapMillis;
|
||||
@ -133,15 +133,17 @@ public class QApplicationJavalinServer
|
||||
{
|
||||
if(resource != null)
|
||||
{
|
||||
config.staticFiles.add("/material-dashboard-overlay");
|
||||
config.staticFiles.add(staticFileConfig -> {
|
||||
staticFileConfig.hostedPath = this.frontendMaterialDashboardHostedPath;
|
||||
staticFileConfig.directory = "/material-dashboard-overlay";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// tell javalin where to find material-dashboard static web assets //
|
||||
// in this case, this path is coming from the qqq-frontend-material-dashboard jar //
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
config.staticFiles.add("/material-dashboard");
|
||||
config.staticFiles.add(staticFileConfig -> {
|
||||
staticFileConfig.hostedPath = this.frontendMaterialDashboardHostedPath;
|
||||
staticFileConfig.directory = "/material-dashboard";
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// set the index page for the SPA from material dashboard //
|
||||
@ -184,7 +186,7 @@ public class QApplicationJavalinServer
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// additional route providers (e.g., application-apis, other middlewares) //
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
for(QJavalinRouteProviderInterface routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
||||
for(QJavalinRouteProvider routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
||||
{
|
||||
routeProvider.setQInstance(qInstance);
|
||||
|
||||
@ -194,6 +196,10 @@ public class QApplicationJavalinServer
|
||||
config.router.apiBuilder(javalinEndpointGroup);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// If the additional route provider has an SPA root defined, add it to the Javalin config. //
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
routeProvider.acceptJavalinConfig(config);
|
||||
}
|
||||
});
|
||||
@ -202,7 +208,7 @@ public class QApplicationJavalinServer
|
||||
// also pass the javalin service into any additionalRouteProviders, //
|
||||
// in case they need additional setup, e.g., before/after handlers. //
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
for(QJavalinRouteProviderInterface routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
||||
for(QJavalinRouteProvider routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
||||
{
|
||||
routeProvider.acceptJavalinService(service);
|
||||
}
|
||||
@ -380,7 +386,7 @@ public class QApplicationJavalinServer
|
||||
}
|
||||
}
|
||||
|
||||
for(QJavalinRouteProviderInterface routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
||||
for(QJavalinRouteProvider routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
||||
{
|
||||
routeProvider.setQInstance(newQInstance);
|
||||
}
|
||||
@ -555,7 +561,7 @@ public class QApplicationJavalinServer
|
||||
/*******************************************************************************
|
||||
** Getter for additionalRouteProviders
|
||||
*******************************************************************************/
|
||||
public List<QJavalinRouteProviderInterface> getAdditionalRouteProviders()
|
||||
public List<QJavalinRouteProvider> getAdditionalRouteProviders()
|
||||
{
|
||||
return (this.additionalRouteProviders);
|
||||
}
|
||||
@ -565,7 +571,7 @@ public class QApplicationJavalinServer
|
||||
/*******************************************************************************
|
||||
** Setter for additionalRouteProviders
|
||||
*******************************************************************************/
|
||||
public void setAdditionalRouteProviders(List<QJavalinRouteProviderInterface> additionalRouteProviders)
|
||||
public void setAdditionalRouteProviders(List<QJavalinRouteProvider> additionalRouteProviders)
|
||||
{
|
||||
this.additionalRouteProviders = additionalRouteProviders;
|
||||
}
|
||||
@ -575,7 +581,7 @@ public class QApplicationJavalinServer
|
||||
/*******************************************************************************
|
||||
** Fluent setter for additionalRouteProviders
|
||||
*******************************************************************************/
|
||||
public QApplicationJavalinServer withAdditionalRouteProviders(List<QJavalinRouteProviderInterface> additionalRouteProviders)
|
||||
public QApplicationJavalinServer withAdditionalRouteProviders(List<QJavalinRouteProvider> additionalRouteProviders)
|
||||
{
|
||||
this.additionalRouteProviders = additionalRouteProviders;
|
||||
return (this);
|
||||
@ -586,7 +592,7 @@ public class QApplicationJavalinServer
|
||||
/*******************************************************************************
|
||||
** Fluent setter to add a single additionalRouteProvider
|
||||
*******************************************************************************/
|
||||
public QApplicationJavalinServer withAdditionalRouteProvider(QJavalinRouteProviderInterface additionalRouteProvider)
|
||||
public QApplicationJavalinServer withAdditionalRouteProvider(QJavalinRouteProvider additionalRouteProvider)
|
||||
{
|
||||
if(this.additionalRouteProviders == null)
|
||||
{
|
||||
|
@ -32,8 +32,9 @@ import io.javalin.config.JavalinConfig;
|
||||
** Interface for classes that can provide a list of endpoints to a javalin
|
||||
** server.
|
||||
*******************************************************************************/
|
||||
public abstract class QJavalinRouteProviderInterface
|
||||
public abstract class QJavalinRouteProvider
|
||||
{
|
||||
private String spaRootPath = null;
|
||||
|
||||
/***************************************************************************
|
||||
** For initial setup when server boots, set the qInstance - but also,
|
||||
@ -41,6 +42,8 @@ public abstract class QJavalinRouteProviderInterface
|
||||
***************************************************************************/
|
||||
public abstract void setQInstance(QInstance qInstance);
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
|
@ -33,6 +33,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
public class JavalinRouteProviderMetaData implements QMetaDataObject
|
||||
{
|
||||
private String hostedPath;
|
||||
private String spaRootPath;
|
||||
|
||||
private String fileSystemPath;
|
||||
private String processName;
|
||||
@ -206,4 +207,35 @@ public class JavalinRouteProviderMetaData implements QMetaDataObject
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for spaRootPath
|
||||
*******************************************************************************/
|
||||
public String getSpaRootPath()
|
||||
{
|
||||
return (this.spaRootPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for spaRootPath
|
||||
*******************************************************************************/
|
||||
public void setSpaRootPath(String spaRootPath)
|
||||
{
|
||||
this.spaRootPath = spaRootPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for spaRootPath
|
||||
*******************************************************************************/
|
||||
public JavalinRouteProviderMetaData withSpaRootPath(String spaRootPath)
|
||||
{
|
||||
this.spaRootPath = spaRootPath;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||
import com.kingsrook.qqq.backend.javalin.QJavalinImplementation;
|
||||
import com.kingsrook.qqq.backend.javalin.QJavalinUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinRouteProviderInterface;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinRouteProvider;
|
||||
import com.kingsrook.qqq.middleware.javalin.metadata.JavalinRouteProviderMetaData;
|
||||
import com.kingsrook.qqq.middleware.javalin.routeproviders.authentication.RouteAuthenticatorInterface;
|
||||
import io.javalin.apibuilder.ApiBuilder;
|
||||
@ -56,7 +56,7 @@ import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class ProcessBasedRouter implements QJavalinRouteProviderInterface
|
||||
public class ProcessBasedRouter extends QJavalinRouteProvider
|
||||
{
|
||||
private static final QLogger LOG = QLogger.getLogger(ProcessBasedRouter.class);
|
||||
|
||||
|
Reference in New Issue
Block a user