feat: 增加prod-api对外转发

dev
huangfeng 1 year ago
parent 73f383321c
commit 6d736fe389

@ -142,6 +142,11 @@
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>org.mitre.dsmiley.httpproxy</groupId>
<artifactId>smiley-http-proxy-servlet</artifactId>
<version>1.12.1</version>
</dependency>
</dependencies>
<build>

@ -0,0 +1,36 @@
package com.xydl.cac.config;
import org.mitre.dsmiley.httpproxy.ProxyServlet;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import java.util.Properties;
@Configuration
public class SolrProxyServletConfiguration implements EnvironmentAware {
@Bean
public ServletRegistrationBean servletRegistrationBean() {
Properties properties = (Properties) bindResult.get();
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new ProxyServlet(), properties.getProperty("servlet_url"));
servletRegistrationBean.addInitParameter(ProxyServlet.P_TARGET_URI, properties.getProperty("target_url"));
servletRegistrationBean.addInitParameter(ProxyServlet.P_LOG, properties.getProperty("logging_enabled", "false"));
return servletRegistrationBean;
}
private BindResult bindResult;
@Override
public void setEnvironment(Environment environment) {
Iterable sources = ConfigurationPropertySources.get(environment);
Binder binder = new Binder(sources);
BindResult bindResult = binder.bind("proxy.solr", Properties.class);
this.bindResult = bindResult;
}
}

@ -24,3 +24,8 @@ spring:
multipart:
max-file-size: 100MB
max-request-size: 100MB
proxy:
solr:
servlet_url: /prod-api/*
target_url: http://127.0.0.1:8082/

@ -24,3 +24,8 @@ spring:
multipart:
max-file-size: 100MB
max-request-size: 100MB
proxy:
solr:
servlet_url: /prod-api/*
target_url: http://127.0.0.1:8082/

Loading…
Cancel
Save