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.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<IWebHostEnvironment>();
// do not provide static files when not in development
if (!env.IsDevelopment())
{
return app;
}
if (path == null && configName == null)
{
IOptions<ViteProxyOptions> options = app.ApplicationServices.GetRequiredService<IOptions<ViteProxyOptions>>();
+1 -1
View File
@@ -15,7 +15,7 @@ public class ViteProxyOptions
/// <summary>
/// Directory where the frontend files are located
/// </summary>
public string WorkingDirectory { get; set; }
public string WorkingDirectory { get; set; } = "";
/// <summary>
/// Whether to enable the proxy or not
+2 -2
View File
@@ -28,7 +28,7 @@ public class ViteProxyService : IHostedService
/// <inheritdoc />
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)