mirror of https://github.com/halo-dev/halo
Support user-center route (#4797)
#### What type of PR is this? /kind feature /area core /area console #### What this PR does / why we need it: This PR add a route to support user-center. #### Does this PR introduce a user-facing change? ```release-note None ```pull/4805/head^2
parent
dcf099691f
commit
b9c0a1f1d0
|
@ -74,4 +74,5 @@ application-local.properties
|
||||||
!application/src/test/resources/themes/*.zip
|
!application/src/test/resources/themes/*.zip
|
||||||
!application/src/main/resources/themes/*.zip
|
!application/src/main/resources/themes/*.zip
|
||||||
application/src/main/resources/console/
|
application/src/main/resources/console/
|
||||||
|
application/src/main/resources/uc/
|
||||||
application/src/main/resources/presets/
|
application/src/main/resources/presets/
|
||||||
|
|
|
@ -29,14 +29,13 @@ import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||||
import org.springframework.web.reactive.resource.EncodedResourceResolver;
|
import org.springframework.web.reactive.resource.EncodedResourceResolver;
|
||||||
import org.springframework.web.reactive.resource.PathResourceResolver;
|
import org.springframework.web.reactive.resource.PathResourceResolver;
|
||||||
import org.springframework.web.reactive.result.view.ViewResolutionResultHandler;
|
import org.springframework.web.reactive.result.view.ViewResolutionResultHandler;
|
||||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import run.halo.app.console.ConsoleProxyFilter;
|
import run.halo.app.console.ProxyFilter;
|
||||||
import run.halo.app.console.WebSocketRequestPredicate;
|
import run.halo.app.console.WebSocketRequestPredicate;
|
||||||
import run.halo.app.core.extension.endpoint.CustomEndpoint;
|
import run.halo.app.core.extension.endpoint.CustomEndpoint;
|
||||||
import run.halo.app.core.extension.endpoint.CustomEndpointsBuilder;
|
import run.halo.app.core.extension.endpoint.CustomEndpointsBuilder;
|
||||||
|
@ -104,11 +103,21 @@ public class WebFluxConfig implements WebFluxConfigurer {
|
||||||
.and(path("/console/**").and(path("/console/assets/**").negate()))
|
.and(path("/console/**").and(path("/console/assets/**").negate()))
|
||||||
.and(accept(MediaType.TEXT_HTML))
|
.and(accept(MediaType.TEXT_HTML))
|
||||||
.and(new WebSocketRequestPredicate().negate());
|
.and(new WebSocketRequestPredicate().negate());
|
||||||
return route(consolePredicate, this::serveConsoleIndex);
|
return route(consolePredicate,
|
||||||
|
request -> this.serveIndex(haloProp.getConsole().getLocation() + "index.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<ServerResponse> serveConsoleIndex(ServerRequest request) {
|
@Bean
|
||||||
var indexLocation = haloProp.getConsole().getLocation() + "index.html";
|
RouterFunction<ServerResponse> ucIndexRedirect() {
|
||||||
|
var consolePredicate = method(HttpMethod.GET)
|
||||||
|
.and(path("/uc/**").and(path("/uc/assets/**").negate()))
|
||||||
|
.and(accept(MediaType.TEXT_HTML))
|
||||||
|
.and(new WebSocketRequestPredicate().negate());
|
||||||
|
return route(consolePredicate,
|
||||||
|
request -> this.serveIndex(haloProp.getUc().getLocation() + "index.html"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mono<ServerResponse> serveIndex(String indexLocation) {
|
||||||
var indexResource = applicationContext.getResource(indexLocation);
|
var indexResource = applicationContext.getResource(indexLocation);
|
||||||
try {
|
try {
|
||||||
return ServerResponse.ok()
|
return ServerResponse.ok()
|
||||||
|
@ -142,6 +151,15 @@ public class WebFluxConfig implements WebFluxConfigurer {
|
||||||
.addResolver(new EncodedResourceResolver())
|
.addResolver(new EncodedResourceResolver())
|
||||||
.addResolver(new PathResourceResolver());
|
.addResolver(new PathResourceResolver());
|
||||||
|
|
||||||
|
// For uc assets
|
||||||
|
registry.addResourceHandler("/uc/assets/**")
|
||||||
|
.addResourceLocations(haloProp.getUc().getLocation() + "assets/")
|
||||||
|
.setCacheControl(cacheControl)
|
||||||
|
.setUseLastModified(useLastModified)
|
||||||
|
.resourceChain(true)
|
||||||
|
.addResolver(new EncodedResourceResolver())
|
||||||
|
.addResolver(new PathResourceResolver());
|
||||||
|
|
||||||
// Additional resource mappings
|
// Additional resource mappings
|
||||||
var staticResources = haloProp.getAttachment().getResourceMappings();
|
var staticResources = haloProp.getAttachment().getResourceMappings();
|
||||||
staticResources.forEach(staticResource -> {
|
staticResources.forEach(staticResource -> {
|
||||||
|
@ -172,7 +190,14 @@ public class WebFluxConfig implements WebFluxConfigurer {
|
||||||
|
|
||||||
@ConditionalOnProperty(name = "halo.console.proxy.enabled", havingValue = "true")
|
@ConditionalOnProperty(name = "halo.console.proxy.enabled", havingValue = "true")
|
||||||
@Bean
|
@Bean
|
||||||
ConsoleProxyFilter consoleProxyFilter() {
|
ProxyFilter consoleProxyFilter() {
|
||||||
return new ConsoleProxyFilter(haloProp);
|
return new ProxyFilter("/console/**", haloProp.getConsole().getProxy());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ConditionalOnProperty(name = "halo.uc.proxy.enabled", havingValue = "true")
|
||||||
|
@Bean
|
||||||
|
ProxyFilter ucProxyFilter() {
|
||||||
|
return new ProxyFilter("/uc/**", haloProp.getUc().getProxy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,10 @@ import org.springframework.web.server.WebFilter;
|
||||||
import org.springframework.web.server.WebFilterChain;
|
import org.springframework.web.server.WebFilterChain;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import run.halo.app.infra.properties.ConsoleProperties.ProxyProperties;
|
import run.halo.app.infra.properties.ProxyProperties;
|
||||||
import run.halo.app.infra.properties.HaloProperties;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ConsoleProxyFilter implements WebFilter {
|
public class ProxyFilter implements WebFilter {
|
||||||
|
|
||||||
private final ProxyProperties proxyProperties;
|
private final ProxyProperties proxyProperties;
|
||||||
|
|
||||||
|
@ -25,14 +24,15 @@ public class ConsoleProxyFilter implements WebFilter {
|
||||||
|
|
||||||
private final WebClient webClient;
|
private final WebClient webClient;
|
||||||
|
|
||||||
public ConsoleProxyFilter(HaloProperties haloProperties) {
|
public ProxyFilter(String pattern, ProxyProperties proxyProperties) {
|
||||||
this.proxyProperties = haloProperties.getConsole().getProxy();
|
this.proxyProperties = proxyProperties;
|
||||||
var consoleMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/console/**");
|
var consoleMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, pattern);
|
||||||
consoleMatcher = new AndServerWebExchangeMatcher(consoleMatcher,
|
consoleMatcher = new AndServerWebExchangeMatcher(consoleMatcher,
|
||||||
new NegatedServerWebExchangeMatcher(new WebSocketServerWebExchangeMatcher()));
|
new NegatedServerWebExchangeMatcher(new WebSocketServerWebExchangeMatcher()));
|
||||||
this.consoleMatcher = consoleMatcher;
|
this.consoleMatcher = consoleMatcher;
|
||||||
this.webClient = WebClient.create(proxyProperties.getEndpoint().toString());
|
this.webClient = WebClient.create(proxyProperties.getEndpoint().toString());
|
||||||
log.info("Initialized ConsoleProxyFilter to proxy console");
|
log.debug("Initialized ProxyFilter to proxy {} to endpoint {}", pattern,
|
||||||
|
proxyProperties.getEndpoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -1,7 +1,6 @@
|
||||||
package run.halo.app.infra.properties;
|
package run.halo.app.infra.properties;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import java.net.URI;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -12,17 +11,4 @@ public class ConsoleProperties {
|
||||||
@Valid
|
@Valid
|
||||||
private ProxyProperties proxy = new ProxyProperties();
|
private ProxyProperties proxy = new ProxyProperties();
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class ProxyProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Console endpoint in development environment to be proxied. e.g.: http://localhost:8090/
|
|
||||||
*/
|
|
||||||
private URI endpoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if the proxy behaviour is enabled. Default is false
|
|
||||||
*/
|
|
||||||
private boolean enabled = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,9 @@ public class HaloProperties implements Validator {
|
||||||
@Valid
|
@Valid
|
||||||
private final ConsoleProperties console = new ConsoleProperties();
|
private final ConsoleProperties console = new ConsoleProperties();
|
||||||
|
|
||||||
|
@Valid
|
||||||
|
private final UcProperties uc = new UcProperties();
|
||||||
|
|
||||||
@Valid
|
@Valid
|
||||||
private final ThemeProperties theme = new ThemeProperties();
|
private final ThemeProperties theme = new ThemeProperties();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package run.halo.app.infra.properties;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ProxyProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Console endpoint in development environment to be proxied. e.g.: http://localhost:8090/
|
||||||
|
*/
|
||||||
|
private URI endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the proxy behaviour is enabled. Default is false
|
||||||
|
*/
|
||||||
|
private boolean enabled = false;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package run.halo.app.infra.properties;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UcProperties {
|
||||||
|
|
||||||
|
private String location = "classpath:/uc/";
|
||||||
|
|
||||||
|
@Valid
|
||||||
|
private ProxyProperties proxy = new ProxyProperties();
|
||||||
|
|
||||||
|
}
|
|
@ -19,6 +19,10 @@ halo:
|
||||||
proxy:
|
proxy:
|
||||||
endpoint: http://localhost:3000/
|
endpoint: http://localhost:3000/
|
||||||
enabled: true
|
enabled: true
|
||||||
|
uc:
|
||||||
|
proxy:
|
||||||
|
endpoint: http://localhost:4000/
|
||||||
|
enabled: true
|
||||||
plugin:
|
plugin:
|
||||||
runtime-mode: development # development, deployment
|
runtime-mode: development # development, deployment
|
||||||
work-dir: ${user.home}/halo2-dev
|
work-dir: ${user.home}/halo2-dev
|
||||||
|
|
Loading…
Reference in New Issue