mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Start support for static-file routing
This commit is contained in:
@ -36,6 +36,7 @@ import com.kingsrook.qqq.backend.javalin.QJavalinImplementation;
|
|||||||
import com.kingsrook.qqq.middleware.javalin.specs.AbstractMiddlewareVersion;
|
import com.kingsrook.qqq.middleware.javalin.specs.AbstractMiddlewareVersion;
|
||||||
import com.kingsrook.qqq.middleware.javalin.specs.v1.MiddlewareVersionV1;
|
import com.kingsrook.qqq.middleware.javalin.specs.v1.MiddlewareVersionV1;
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
|
import io.javalin.apibuilder.EndpointGroup;
|
||||||
import io.javalin.http.Context;
|
import io.javalin.http.Context;
|
||||||
import org.apache.commons.lang.BooleanUtils;
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
@ -166,7 +167,14 @@ public class QApplicationJavalinServer
|
|||||||
for(QJavalinRouteProviderInterface routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
for(QJavalinRouteProviderInterface routeProvider : CollectionUtils.nonNullList(additionalRouteProviders))
|
||||||
{
|
{
|
||||||
routeProvider.setQInstance(qInstance);
|
routeProvider.setQInstance(qInstance);
|
||||||
config.router.apiBuilder(routeProvider.getJavalinEndpointGroup());
|
|
||||||
|
EndpointGroup javalinEndpointGroup = routeProvider.getJavalinEndpointGroup();
|
||||||
|
if(javalinEndpointGroup != null)
|
||||||
|
{
|
||||||
|
config.router.apiBuilder(javalinEndpointGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
routeProvider.acceptJavalinConfig(config);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ package com.kingsrook.qqq.middleware.javalin;
|
|||||||
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
import io.javalin.apibuilder.EndpointGroup;
|
import io.javalin.apibuilder.EndpointGroup;
|
||||||
|
import io.javalin.config.JavalinConfig;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -42,6 +43,22 @@ public interface QJavalinRouteProviderInterface
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
**
|
**
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
EndpointGroup getJavalinEndpointGroup();
|
default EndpointGroup getJavalinEndpointGroup()
|
||||||
|
{
|
||||||
|
/////////////////////////////
|
||||||
|
// no endpoints at default //
|
||||||
|
/////////////////////////////
|
||||||
|
return (null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
default void acceptJavalinConfig(JavalinConfig config)
|
||||||
|
{
|
||||||
|
/////////////////////
|
||||||
|
// noop at default //
|
||||||
|
/////////////////////
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.middleware.javalin.routeproviders;
|
||||||
|
|
||||||
|
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
|
import com.kingsrook.qqq.middleware.javalin.QJavalinRouteProviderInterface;
|
||||||
|
import io.javalin.config.JavalinConfig;
|
||||||
|
import io.javalin.http.staticfiles.Location;
|
||||||
|
import io.javalin.http.staticfiles.StaticFileConfig;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public class SimpleFileSystemDirectoryRouter implements QJavalinRouteProviderInterface
|
||||||
|
{
|
||||||
|
private final String hostedPath;
|
||||||
|
private final String fileSystemPath;
|
||||||
|
private QInstance qInstance;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Constructor
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public SimpleFileSystemDirectoryRouter(String hostedPath, String fileSystemPath)
|
||||||
|
{
|
||||||
|
this.hostedPath = hostedPath;
|
||||||
|
this.fileSystemPath = fileSystemPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void setQInstance(QInstance qInstance)
|
||||||
|
{
|
||||||
|
this.qInstance = qInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void acceptJavalinConfig(JavalinConfig config)
|
||||||
|
{
|
||||||
|
config.staticFiles.add((StaticFileConfig userConfig) ->
|
||||||
|
{
|
||||||
|
userConfig.hostedPath = hostedPath;
|
||||||
|
userConfig.directory = fileSystemPath;
|
||||||
|
userConfig.location = Location.EXTERNAL;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user