Skip to content

Commit 8c372b1

Browse files
committed
switch to NodeProxy
1 parent fecf8c7 commit 8c372b1

4 files changed

Lines changed: 31 additions & 529 deletions

File tree

TechStacks.Client/package-lock.json

Lines changed: 0 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TechStacks/Program.cs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using TechStacks;
1212
using TechStacks.Data;
1313
using TechStacks.ServiceInterface;
14-
using MyApp;
1514

1615
AppHost.RegisterLicense();
1716
var builder = WebApplication.CreateBuilder(args);
@@ -108,32 +107,37 @@
108107
});
109108

110109
var app = builder.Build();
111-
app.UseForwardedHeaders();
112-
app.UseWebSockets();
110+
// Proxy 404s to Next.js (except for API/backend routes) must be registered before endpoints
111+
var nodeProxy = new NodeProxy("http://localhost:3000") {
112+
Log = app.Logger
113+
};
113114

114-
app.UseMigrationsEndPoint();
115+
app.UseForwardedHeaders();
115116

116117
// Configure the HTTP request pipeline.
117118
if (app.Environment.IsDevelopment())
118119
{
119-
app.UseExceptionHandler("/Home/Error");
120-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
121-
app.UseHsts();
122-
app.UseHttpsRedirection();
120+
app.UseDeveloperExceptionPage();
121+
app.UseMigrationsEndPoint();
122+
123+
app.MapNotFoundToNode(nodeProxy);
123124
}
124125
else
125126
{
126-
// Production-specific middleware (if needed) can go here
127+
app.UseExceptionHandler("/Home/Error");
128+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
129+
app.UseHsts();
127130
}
128131

129-
// Proxy 404s to Next.js (except for API/backend routes) must be registered before endpoints
130-
var nodeClient = Proxy.CreateNodeClient();
131-
app.MapNotFoundToNode(nodeClient);
132-
133-
app.UseStaticFiles(); // static assets are served by Next.js
134-
app.UseCookiePolicy();
132+
app.UseDefaultFiles();
133+
app.UseStaticFiles();
134+
app.MapCleanUrls();
135135
app.UseCors();
136136

137+
app.UseHttpsRedirection();
138+
app.UseAuthorization();
139+
app.MapRazorPages();
140+
137141
// GitHub OAuth endpoint
138142
app.MapGet("/auth/github", (
139143
HttpContext context,
@@ -167,22 +171,20 @@
167171
// Proxy development HMR WebSocket to the Next.js server
168172
if (app.Environment.IsDevelopment())
169173
{
170-
app.MapNextHmr(nodeClient);
174+
app.UseWebSockets();
175+
app.MapNextHmr(nodeProxy);
171176

172177
// Start the Next.js dev server if the Next.js lockfile does not exist
173-
var process = app.StartNodeProcess(
178+
app.RunNodeProcess(nodeProxy,
174179
lockFile: "../TechStacks.Client/dist/lock",
175180
workingDirectory: "../TechStacks.Client");
176-
if (process != null)
177-
{
178-
Console.WriteLine("Started Next.js dev server");
179-
}
180-
else
181-
{
182-
Console.WriteLine("Next.js dev server already running");
183-
}
184-
}
185181

186-
app.MapFallbackToNode(nodeClient);
182+
app.MapFallbackToNode(nodeProxy);
183+
}
184+
else
185+
{
186+
// Map fallback to index.html in production (MyApp.Client/dist > wwwroot)
187+
app.MapFallbackToFile("index.html");
188+
}
187189

188190
app.Run();

0 commit comments

Comments
 (0)