Add proxy env
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
<env name="DB_URL" value="jdbc:postgresql://192.168.0.10:5432/telegabot" />
|
<env name="DB_URL" value="jdbc:postgresql://192.168.0.10:5432/telegabot" />
|
||||||
<env name="DB_USER" value="postgres" />
|
<env name="DB_USER" value="postgres" />
|
||||||
<env name="OPENROUTER_API_KEY" value="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" />
|
<env name="OPENROUTER_API_KEY" value="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" />
|
||||||
|
<env name="PROXY_HOST" value="192.168.0.5" />
|
||||||
|
<env name="PROXY_PORT" value="1984" />
|
||||||
</envs>
|
</envs>
|
||||||
<module name="TelegaBot.main" />
|
<module name="TelegaBot.main" />
|
||||||
<option name="SPRING_BOOT_MAIN_CLASS" value="ru.cathub.telegabot.TelegaBotApplication" />
|
<option name="SPRING_BOOT_MAIN_CLASS" value="ru.cathub.telegabot.TelegaBotApplication" />
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ COPY gradle ./gradle
|
|||||||
RUN ./gradlew clean build -x test
|
RUN ./gradlew clean build -x test
|
||||||
|
|
||||||
# Запуск приложения
|
# Запуск приложения
|
||||||
FROM openjdk:21-jdk-slim
|
FROM eclipse-temurin:21-jre-jammy
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=build /app/build/libs/*.jar app.jar
|
COPY --from=build /app/build/libs/*.jar app.jar
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,41 @@
|
|||||||
package ru.cathub.telegabot.configuration;
|
package ru.cathub.telegabot.configuration;
|
||||||
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
// Добавлены импорты для прокси, если они используются в бине RestTemplate
|
|
||||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties
|
@EnableConfigurationProperties
|
||||||
@ConfigurationProperties(prefix = "openrouter.api")
|
@ConfigurationProperties(prefix = "openrouter.api")
|
||||||
@Setter // <-- Аннотация @Setter осталась, она сгенерирует сеттеры для key и url
|
@Setter
|
||||||
public class OpenRouterConfig {
|
public class OpenRouterConfig {
|
||||||
private String key;
|
private String key;
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
@Value("${proxy.host:}")
|
||||||
|
private String proxyHost;
|
||||||
|
|
||||||
|
@Value("${proxy.port:0}")
|
||||||
|
private int proxyPort;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RestTemplate restTemplate() {
|
public RestTemplate restTemplate() {
|
||||||
// Логика создания RestTemplate с прокси или без - ВЕРНО!
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||||
// Пример с прокси:
|
|
||||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
if (proxyHost != null && !proxyHost.isBlank() && proxyPort > 0) {
|
||||||
factory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.0.5", 1984))); // Убедитесь, что адрес и порт верны
|
factory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
|
||||||
return new RestTemplate(factory);
|
}
|
||||||
// Пример без прокси:
|
|
||||||
// return new RestTemplate();
|
return new RestTemplate(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Геттеры для key и url будут сгенерированы Lombok @Setter,
|
|
||||||
// но лучше явно добавить @Getter для них, если они нужны только для чтения внутри сервиса
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
@@ -40,6 +43,4 @@ public class OpenRouterConfig {
|
|||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Метод getModel() удален - ВЕРНО!
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,20 @@ import org.telegram.telegrambots.meta.generics.TelegramClient;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class TelegramConfig {
|
public class TelegramConfig {
|
||||||
|
|
||||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
@Value("${proxy.host:}")
|
||||||
.proxy(new java.net.Proxy(java.net.Proxy.Type.HTTP, new java.net.InetSocketAddress("192.168.0.5", 1984)))
|
private String proxyHost;
|
||||||
.build();
|
|
||||||
|
@Value("${proxy.port:0}")
|
||||||
|
private int proxyPort;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TelegramClient telegramClient(@Value("${bot.token}") String token) {
|
public TelegramClient telegramClient(@Value("${bot.token}") String token) {
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (proxyHost != null && !proxyHost.isBlank() && proxyPort > 0) {
|
||||||
|
builder.proxy(new java.net.Proxy(java.net.Proxy.Type.HTTP, new java.net.InetSocketAddress(proxyHost, proxyPort)));
|
||||||
|
}
|
||||||
|
OkHttpClient okHttpClient = builder.build();
|
||||||
|
|
||||||
return new OkHttpTelegramClient(okHttpClient,token);
|
return new OkHttpTelegramClient(okHttpClient, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ spring.datasource.password=${DB_PASSWORD}
|
|||||||
# OpenRouter AI
|
# OpenRouter AI
|
||||||
openrouter.api.key=${OPENROUTER_API_KEY}
|
openrouter.api.key=${OPENROUTER_API_KEY}
|
||||||
|
|
||||||
|
# Proxy Configuration (optional)
|
||||||
|
proxy.host=${PROXY_HOST:}
|
||||||
|
proxy.port=${PROXY_PORT:0}
|
||||||
|
|
||||||
# JobRunr Configuration
|
# JobRunr Configuration
|
||||||
|
|
||||||
org.jobrunr.job-scheduler.enabled=true
|
org.jobrunr.job-scheduler.enabled=true
|
||||||
|
|||||||
Reference in New Issue
Block a user