-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed graphql and catch all forward to react index.html
- Loading branch information
1 parent
5d088c8
commit 8aa4f0c
Showing
11 changed files
with
1,006 additions
and
991 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 41 additions & 5 deletions
46
server/src/main/java/me/retrodaredevil/solarthing/rest/WebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
package me.retrodaredevil.solarthing.rest; | ||
|
||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.graphql.ExecutionGraphQlService; | ||
import org.springframework.graphql.execution.DefaultExecutionGraphQlService; | ||
import org.springframework.graphql.execution.GraphQlSource; | ||
import org.springframework.graphql.server.WebGraphQlHandler; | ||
import org.springframework.graphql.server.webmvc.GraphQlHttpHandler; | ||
import org.springframework.web.servlet.HandlerMapping; | ||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.servlet.function.RequestPredicates; | ||
import org.springframework.web.servlet.function.RouterFunction; | ||
import org.springframework.web.servlet.function.RouterFunctions; | ||
import org.springframework.web.servlet.function.ServerResponse; | ||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; | ||
|
||
@Configuration | ||
public class WebConfiguration implements WebMvcConfigurer { | ||
// thanks https://stackoverflow.com/a/42998817/5434860 | ||
@Override | ||
public void addViewControllers(ViewControllerRegistry registry) { | ||
public class WebConfiguration { | ||
|
||
@Bean | ||
public HandlerMapping catchAllHandlerMapping(ApplicationContext applicationContext) { | ||
// related to https://stackoverflow.com/a/42998817/5434860 | ||
// We have to do it this way, so we can set the order so this has the lowest precedence | ||
var registry = new ViewControllerRegistry(applicationContext) { | ||
@Override | ||
public SimpleUrlHandlerMapping buildHandlerMapping() { | ||
return super.buildHandlerMapping(); | ||
} | ||
}; | ||
registry.setOrder(5); | ||
registry.addViewController("/{spring:[a-zA-Z0-9-_]+}") | ||
.setViewName("forward:/"); | ||
return registry.buildHandlerMapping(); | ||
} | ||
|
||
@Bean | ||
public RouterFunction<ServerResponse> graphQLRouterFunction(GraphQlSource graphQlSource) { | ||
ExecutionGraphQlService executionGraphQlService = new DefaultExecutionGraphQlService(graphQlSource); | ||
GraphQlHttpHandler handler = new GraphQlHttpHandler( | ||
WebGraphQlHandler.builder(executionGraphQlService) | ||
.build() | ||
); | ||
return RouterFunctions.route(RequestPredicates.path("/graphql"), handler::handleRequest); | ||
// return RouterFunctions.route() | ||
// .POST("/graphql", RequestPredicates.contentType(MediaType.APPLICATION_JSON), handler::handleRequest) | ||
// .build() | ||
// ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
server/src/main/java/me/retrodaredevil/solarthing/rest/spring/ApplicationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package me.retrodaredevil.solarthing.rest.spring; | ||
|
||
import org.springframework.beans.factory.config.CustomEditorConfigurer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class ApplicationConfig { | ||
|
||
@Bean | ||
public CustomEditorConfigurer customEditorConfigurer() { | ||
CustomEditorConfigurer configurer = new CustomEditorConfigurer(); | ||
configurer.setCustomEditors(Map.of( | ||
Path.class, NioPathPropertyEditorSupport.class | ||
)); | ||
|
||
return configurer; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../src/main/java/me/retrodaredevil/solarthing/rest/spring/NioPathPropertyEditorSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package me.retrodaredevil.solarthing.rest.spring; | ||
|
||
import java.beans.PropertyEditorSupport; | ||
import java.nio.file.Path; | ||
|
||
public class NioPathPropertyEditorSupport extends PropertyEditorSupport { | ||
@Override | ||
public String getAsText() { | ||
Path path = (Path) getValue(); | ||
return path.toString(); | ||
} | ||
|
||
@Override | ||
public void setAsText(String text) throws IllegalArgumentException { | ||
setValue(Path.of(text)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.