diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 948d0c1..f641b23 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,6 +16,16 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Clear directory + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.SSH_USER }} + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_KEY }} + script: | + rm -rf ${{ secrets.TARGET_DIR }}/ffsaf/src/* + - name: Copy repository contents to vps via scp uses: appleboy/scp-action@v0.1.4 # Latest in date when creating the workflow with: @@ -26,6 +36,20 @@ jobs: source: "." target: ${{ secrets.TARGET_DIR }}/ffsaf # Need to create it first on the VPS + - name: Build site and copy it + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.SSH_USER }} + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_KEY }} + script: | + cd ${{ secrets.TARGET_DIR }}/ffsaf/src/main/webapp + cp ${{ secrets.TARGET_DIR }}/vite.env .env + npm run build + rm -rf ${{ secrets.TARGET_DIR }}/ffsaf/src/main/resources/META-INF/resources + mv dist ${{ secrets.TARGET_DIR }}/ffsaf/src/main/resources/META-INF/resources + - name: Build application uses: appleboy/ssh-action@v1.0.0 with: diff --git a/.gitignore b/.gitignore index 3175934..0d8dfae 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,6 @@ nb-configuration.xml # Custom /config/application.properties -/cle_prive.jks \ No newline at end of file +/cle_prive.jks +/src/main/resources/META-INF/resources/ +/media/ diff --git a/pom.xml b/pom.xml index 1a44c2a..836929b 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ io.quarkiverse.quinoa - quarkus-quinoa-deployment + quarkus-quinoa 2.3.2 diff --git a/src/main/java/fr/titionfire/ffsaf/FrontendForwardingFilter.java b/src/main/java/fr/titionfire/ffsaf/FrontendForwardingFilter.java new file mode 100644 index 0000000..b8392bc --- /dev/null +++ b/src/main/java/fr/titionfire/ffsaf/FrontendForwardingFilter.java @@ -0,0 +1,75 @@ +package fr.titionfire.ffsaf; + +import io.vertx.core.http.HttpServerRequest; +import jakarta.annotation.Priority; +import jakarta.ws.rs.Priorities; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.container.ResourceInfo; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.Provider; +import org.jboss.logging.Logger; + +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import java.util.Scanner; + +@Provider +@Priority(Priorities.USER) +public class FrontendForwardingFilter implements ContainerResponseFilter { + + private static final Logger LOG = Logger.getLogger(FrontendForwardingFilter.class); + + @Context + UriInfo info; + + @Context + HttpServerRequest request; + + @Context + ResourceInfo resourceInfo; + + private static String text = null; + + private static final String API_NAMESPACE_REGEX = "^/(api/.*|api)"; + private static final String FILENAME_REGEX = "^/.*\\.[^.]+$"; + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { + + final String method = requestContext.getMethod(); + final String path = info.getPath(); + final String address = request.remoteAddress().toString(); + + LOG.infof("Request %s %s from IP %s", method, path, address); + + int status = responseContext.getStatus(); + if (status != 404 && !(status == 405 && "GET".equals(requestContext.getMethod()))) { + return; + } + + boolean isApiNamespace = path.matches(API_NAMESPACE_REGEX); + if (isApiNamespace) { + return; + } + boolean isFilename = path.matches(FILENAME_REGEX); + if (isFilename) { + return; + } + boolean actualErrorResponse = resourceInfo != null && resourceInfo.getResourceMethod() != null; + if (actualErrorResponse) { + return; + } + + LOG.info("redirect"); + + if (text == null) + text = new Scanner(Objects.requireNonNull(this.getClass().getResourceAsStream("/META-INF/resources/index.html")), + StandardCharsets.UTF_8).useDelimiter("\\A").next(); + responseContext.setStatus(200); + responseContext.setEntity(text, null, MediaType.TEXT_HTML_TYPE); + } +} diff --git a/src/main/resources/META-INF/resources/index.html b/src/main/resources/META-INF/resources/index.html deleted file mode 100644 index 0775b23..0000000 --- a/src/main/resources/META-INF/resources/index.html +++ /dev/null @@ -1,373 +0,0 @@ - - - - - ffsaf-site - 1.0-SNAPSHOT - - - -
-
-
- - - - - quarkus_logo_horizontal_rgb_1280px_reverse - - - - - - - - - - - - - - - - - - -
-
-
- -
-
-
-

You just made a Quarkus application.

-

This page is served by Quarkus.

- Visit the Dev UI -

This page: src/main/resources/META-INF/resources/index.html

-

App configuration: src/main/resources/application.properties

-

Static assets: src/main/resources/META-INF/resources/

-

Code: src/main/java

-

Generated starter code:

-
    -
  • - RESTEasy Reactive Easily start your Reactive RESTful Web Services -
    @Path: /hello -
    Related guide -
  • -
  • - RESTEasy Reactive Qute Create your web page using Quarkus RESTEasy Reactive & Qute -
    @Path: /some-page -
    Related guide -
  • - -
-
-
-

Selected extensions

-
    -
  • - RESTEasy Reactive Jackson -
  • -
  • - RESTEasy Reactive Qute -
  • -
  • Reactive MySQL client (guide) -
  • -
  • - RESTEasy Reactive (guide) -
  • -
  • Hibernate ORM with - Panache (guide) -
  • -
  • Reactive PostgreSQL client (guide) -
  • -
-
Documentation
-

Practical step-by-step guides to help you achieve a specific goal. Use them to help get your work - done.

-
Set up your IDE
-

Everyone has a favorite IDE they like to use to code. Learn how to configure yours to maximize your - Quarkus productivity.

-
-
-
- - diff --git a/src/main/webapp/src/hooks/useAuth.jsx b/src/main/webapp/src/hooks/useAuth.jsx index ad42e19..acbc082 100644 --- a/src/main/webapp/src/hooks/useAuth.jsx +++ b/src/main/webapp/src/hooks/useAuth.jsx @@ -1,4 +1,4 @@ -import {createContext, useContext, useEffect, useReducer} from "react"; +import {createContext, useContext, useReducer} from "react"; const AuthContext = createContext(undefined); const AuthDispatchContext = createContext(null); @@ -24,20 +24,17 @@ export function KeycloakContextProvider({children}) { function authReducer(auth, action) { switch (action.type) { case 'init': { - const token = localStorage.getItem("access_token"); return { - token: token, - refresh: localStorage.getItem("refresh_token"), is_authenticated: action.val, - data: action.val ? JSON.parse(atob(token.split('.')[1])) : null + data: {realm_access: {roles: ["federation_admin"]}} + //data: action.val ? JSON.parse(atob(token.split('.')[1])) : null } } case 'update': { return { ...auth, - token: action.token, - refresh: action.refresh, - data: JSON.parse(atob(action.token.split('.')[1])) + data: {realm_access: {roles: ["federation_admin"]}} + // data: JSON.parse(atob(action.token.split('.')[1])) } } case 'invalidate': {