do not run proxy service when not in dev env

This commit is contained in:
2026-03-25 12:58:20 +01:00
parent ae1efdc527
commit 214938b966
3 changed files with 10 additions and 3 deletions
@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace ViteProxy; namespace ViteProxy;
@@ -19,6 +20,12 @@ public static class ViteProxyApplicationBuilderExtensions
{ {
IWebHostEnvironment env = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>(); IWebHostEnvironment env = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>();
// do not provide static files when not in development
if (!env.IsDevelopment())
{
return app;
}
if (path == null && configName == null) if (path == null && configName == null)
{ {
IOptions<ViteProxyOptions> options = app.ApplicationServices.GetRequiredService<IOptions<ViteProxyOptions>>(); IOptions<ViteProxyOptions> options = app.ApplicationServices.GetRequiredService<IOptions<ViteProxyOptions>>();
+1 -1
View File
@@ -15,7 +15,7 @@ public class ViteProxyOptions
/// <summary> /// <summary>
/// Directory where the frontend files are located /// Directory where the frontend files are located
/// </summary> /// </summary>
public string WorkingDirectory { get; set; } public string WorkingDirectory { get; set; } = "";
/// <summary> /// <summary>
/// Whether to enable the proxy or not /// Whether to enable the proxy or not
+2 -2
View File
@@ -28,7 +28,7 @@ public class ViteProxyService : IHostedService
/// <inheritdoc /> /// <inheritdoc />
public async Task StartAsync(CancellationToken cancellationToken) public async Task StartAsync(CancellationToken cancellationToken)
{ {
if (!this._options.Enabled) if (!_options.Enabled || !_env.IsDevelopment())
{ {
return; return;
} }
@@ -38,7 +38,7 @@ public class ViteProxyService : IHostedService
// start vite server // start vite server
ProcessProxy viteProcess = await StartDevServer(_options.Port); ProcessProxy viteProcess = await StartDevServer(_options.Port);
_logger.LogInformation("vite listening on: http://localhost:{port} (path: {workingDirectory})", _options.Port, this._workingDirectory.Path); _logger.LogInformation("vite listening on: http://localhost:{port} (path: {workingDirectory})", _options.Port, _workingDirectory.Path);
} }
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)