From 214938b966083196fe2ded03fe2d5377c6fd9809 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Wed, 25 Mar 2026 12:58:20 +0100 Subject: [PATCH] do not run proxy service when not in dev env --- src/ViteProxyApplicationBuilderExtensions.cs | 7 +++++++ src/ViteProxyOptions.cs | 2 +- src/ViteProxyService.cs | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ViteProxyApplicationBuilderExtensions.cs b/src/ViteProxyApplicationBuilderExtensions.cs index 615a7ee..bd2828d 100644 --- a/src/ViteProxyApplicationBuilderExtensions.cs +++ b/src/ViteProxyApplicationBuilderExtensions.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; namespace ViteProxy; @@ -19,6 +20,12 @@ public static class ViteProxyApplicationBuilderExtensions { IWebHostEnvironment env = app.ApplicationServices.GetRequiredService(); + // do not provide static files when not in development + if (!env.IsDevelopment()) + { + return app; + } + if (path == null && configName == null) { IOptions options = app.ApplicationServices.GetRequiredService>(); diff --git a/src/ViteProxyOptions.cs b/src/ViteProxyOptions.cs index a7ebba3..9eabe70 100644 --- a/src/ViteProxyOptions.cs +++ b/src/ViteProxyOptions.cs @@ -15,7 +15,7 @@ public class ViteProxyOptions /// /// Directory where the frontend files are located /// - public string WorkingDirectory { get; set; } + public string WorkingDirectory { get; set; } = ""; /// /// Whether to enable the proxy or not diff --git a/src/ViteProxyService.cs b/src/ViteProxyService.cs index e7b9d70..b4460ea 100644 --- a/src/ViteProxyService.cs +++ b/src/ViteProxyService.cs @@ -28,7 +28,7 @@ public class ViteProxyService : IHostedService /// public async Task StartAsync(CancellationToken cancellationToken) { - if (!this._options.Enabled) + if (!_options.Enabled || !_env.IsDevelopment()) { return; } @@ -38,7 +38,7 @@ public class ViteProxyService : IHostedService // start vite server 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)