|
99 | 99 | }); |
100 | 100 |
|
101 | 101 | var app = builder.Build(); |
102 | | - |
103 | | -var nextServerBase = app.Environment.IsDevelopment() |
104 | | - ? new Uri("http://localhost:3000") |
105 | | - : new Uri("http://127.0.0.1:3000"); |
106 | | - |
107 | | -var allowInvalidCertsForNext = false; // No HTTPS when proxying to Next internally |
108 | | - |
109 | | -HttpMessageHandler nextHandler = allowInvalidCertsForNext |
110 | | - ? new HttpClientHandler |
111 | | - { |
112 | | - ServerCertificateCustomValidationCallback = |
113 | | - HttpClientHandler.DangerousAcceptAnyServerCertificateValidator |
114 | | - } |
115 | | - : new HttpClientHandler(); |
116 | | - |
117 | | -var nextClient = new HttpClient(nextHandler) |
118 | | -{ |
119 | | - BaseAddress = nextServerBase |
120 | | -}; |
121 | | - |
122 | 102 | app.UseForwardedHeaders(); |
123 | 103 | app.UseWebSockets(); |
124 | 104 |
|
|
140 | 120 | } |
141 | 121 |
|
142 | 122 | // After all .NET middleware has run, let Next.js handle 404s |
| 123 | +var nextClient = Proxy.CreateNodeClient(); |
143 | 124 | Proxy.MapNotFoundToNode(app, nextClient, ignorePaths:[ |
144 | 125 | "/api", |
145 | 126 | "/auth", |
|
174 | 155 | app.MapRazorPages(); |
175 | 156 | app.MapAdditionalIdentityEndpoints(); |
176 | 157 |
|
177 | | -// Proxy development HMR WebSocket and fallback routes to the Next server |
| 158 | +// Proxy development HMR WebSocket and fallback routes to the Next.js server |
178 | 159 | if (app.Environment.IsDevelopment()) |
179 | 160 | { |
180 | 161 | app.Map("/_next/webpack-hmr", async context => |
181 | 162 | { |
182 | 163 | if (context.WebSockets.IsWebSocketRequest) |
183 | 164 | { |
184 | | - await Proxy.WebSocketToNode(context, nextServerBase, allowInvalidCertsForNext); |
| 165 | + await Proxy.WebSocketToNode(context, nextClient.BaseAddress!, allowInvalidCerts:true); |
185 | 166 | } |
186 | 167 | else |
187 | 168 | { |
|
214 | 195 | } |
215 | 196 | } |
216 | 197 |
|
217 | | -// Fallback: any unmatched route goes to Next.js |
| 198 | +// Fallback: Proxy any unmatched routes to Next.js |
218 | 199 | app.MapFallback(context => Proxy.HttpToNode(context, nextClient)); |
219 | 200 |
|
220 | 201 | app.Run(); |
0 commit comments