|
11 | 11 | using TechStacks; |
12 | 12 | using TechStacks.Data; |
13 | 13 | using TechStacks.ServiceInterface; |
14 | | -using MyApp; |
15 | 14 |
|
16 | 15 | AppHost.RegisterLicense(); |
17 | 16 | var builder = WebApplication.CreateBuilder(args); |
|
108 | 107 | }); |
109 | 108 |
|
110 | 109 | 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 | +}; |
113 | 114 |
|
114 | | -app.UseMigrationsEndPoint(); |
| 115 | +app.UseForwardedHeaders(); |
115 | 116 |
|
116 | 117 | // Configure the HTTP request pipeline. |
117 | 118 | if (app.Environment.IsDevelopment()) |
118 | 119 | { |
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); |
123 | 124 | } |
124 | 125 | else |
125 | 126 | { |
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(); |
127 | 130 | } |
128 | 131 |
|
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(); |
135 | 135 | app.UseCors(); |
136 | 136 |
|
| 137 | +app.UseHttpsRedirection(); |
| 138 | +app.UseAuthorization(); |
| 139 | +app.MapRazorPages(); |
| 140 | + |
137 | 141 | // GitHub OAuth endpoint |
138 | 142 | app.MapGet("/auth/github", ( |
139 | 143 | HttpContext context, |
|
167 | 171 | // Proxy development HMR WebSocket to the Next.js server |
168 | 172 | if (app.Environment.IsDevelopment()) |
169 | 173 | { |
170 | | - app.MapNextHmr(nodeClient); |
| 174 | + app.UseWebSockets(); |
| 175 | + app.MapNextHmr(nodeProxy); |
171 | 176 |
|
172 | 177 | // Start the Next.js dev server if the Next.js lockfile does not exist |
173 | | - var process = app.StartNodeProcess( |
| 178 | + app.RunNodeProcess(nodeProxy, |
174 | 179 | lockFile: "../TechStacks.Client/dist/lock", |
175 | 180 | 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 | | -} |
185 | 181 |
|
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 | +} |
187 | 189 |
|
188 | 190 | app.Run(); |
0 commit comments