-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade AspNetCore React AdvancedSearch sample to .NET 8 #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
97b9bfc
0bf81ba
621d3be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,71 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> | ||
| <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion> | ||
| <IsPackable>false</IsPackable> | ||
| <SpaRoot>ClientApp\</SpaRoot> | ||
| <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes> | ||
| <UserSecretsId>EqDemo.AspNetCoreReact.AdvancedSearch</UserSecretsId> | ||
| <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.1" /> | ||
| <PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.7" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" /> | ||
| <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.34.0" /> | ||
| <PackageReference Include="System.Data.SqlClient" Version="4.8.6" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <!-- DB initialization packages. They are not necessary for EasyQuery working and can be removed in production --> | ||
| <PackageReference Include="Korzh.DbUtils.Import" Version="1.4.1" /> | ||
| <PackageReference Include="Korzh.DbUtils.SqlServer" Version="1.4.1" /> | ||
| <PackageReference Include="Korzh.DbUtils.Sqlite" Version="1.4.1" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="EasyData.Exporters.ClosedXML" Version="1.5.9" /> | ||
| <PackageReference Include="EasyData.Exporters.PdfSharp" Version="1.5.9" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Korzh.EasyQuery.AspNetCore" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.EntityFrameworkCore.Relational" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.SqlServerGate" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.SqLiteGate" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.DataExport" Version="7.4.0" /> | ||
| <PackageReference Include="System.Drawing.Common" Version="4.7.2" /> | ||
| <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.34.0" /> | ||
| <PackageReference Include="System.Net.Http" Version="4.3.4" /> | ||
| <PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <!-- Don't publish the SPA source files, but do show them in the project files list --> | ||
| <Content Remove="$(SpaRoot)**" /> | ||
| <None Remove="$(SpaRoot)**" /> | ||
| <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" /> | ||
| </ItemGroup> | ||
| <Target Name="DebugEnsureNodeEnv" BeforeTargets="PreBuildEvent" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') "> | ||
| <!-- Ensure Node.js is installed --> | ||
| <Exec Command="node --version" ContinueOnError="true"> | ||
| <Output TaskParameter="ExitCode" PropertyName="ErrorCode" /> | ||
| </Exec> | ||
| <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." /> | ||
| <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." /> | ||
| <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> | ||
| </Target> | ||
| <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish"> | ||
| <!-- As part of publishing, ensure the JS resources are freshly built in production mode --> | ||
| <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> | ||
| <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" /> | ||
| <!-- Include the newly-built files in the publish output --> | ||
| <ItemGroup> | ||
| <DistFiles Include="$(SpaRoot)build\**" /> | ||
| <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)"> | ||
| <RelativePath>%(DistFiles.Identity)</RelativePath> | ||
| <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
| </ResolvedFileToPublish> | ||
| </ItemGroup> | ||
| </Target> | ||
| </Project> | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> | ||
| <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion> | ||
| <IsPackable>false</IsPackable> | ||
| <SpaRoot>ClientApp\</SpaRoot> | ||
| <!-- ClientApp uses Create React App; `npm start` runs `react-scripts start`, | ||
| which serves on http://localhost:3000 by default. SpaProxyServerUrl must | ||
| match that URL so Microsoft.AspNetCore.SpaProxy can detect when the dev | ||
| server is ready. --> | ||
| <SpaProxyServerUrl>http://localhost:3000</SpaProxyServerUrl> | ||
| <SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand> | ||
| <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes> | ||
| <UserSecretsId>EqDemo.AspNetCoreReact.AdvancedSearch</UserSecretsId> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.26" /> | ||
| <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.3" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.26" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.26" /> | ||
| <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.7.1" /> | ||
| <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.7.1" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <!-- DB initialization packages. They are not necessary for EasyQuery working and can be removed in production --> | ||
| <PackageReference Include="Korzh.DbUtils.Import" Version="1.4.1" /> | ||
| <PackageReference Include="Korzh.DbUtils.SqlServer" Version="1.4.1" /> | ||
| <PackageReference Include="Korzh.DbUtils.Sqlite" Version="1.4.1" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="EasyData.Exporters.ClosedXML" Version="1.5.9" /> | ||
| <PackageReference Include="EasyData.Exporters.PdfSharp" Version="1.5.9" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Korzh.EasyQuery.AspNetCore" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.EntityFrameworkCore.Relational" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.SqlServerGate" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.SqLiteGate" Version="7.4.0" /> | ||
| <PackageReference Include="Korzh.EasyQuery.DataExport" Version="7.4.0" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <!-- Don't publish the SPA source files, but do show them in the project files list --> | ||
| <Content Remove="$(SpaRoot)**" /> | ||
| <None Remove="$(SpaRoot)**" /> | ||
| <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" /> | ||
| </ItemGroup> | ||
| <Target Name="DebugEnsureNodeEnv" BeforeTargets="PreBuildEvent" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') "> | ||
| <!-- Ensure Node.js is installed --> | ||
| <Exec Command="node --version" ContinueOnError="true"> | ||
| <Output TaskParameter="ExitCode" PropertyName="ErrorCode" /> | ||
| </Exec> | ||
| <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." /> | ||
| <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." /> | ||
| <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> | ||
| </Target> | ||
| <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish"> | ||
| <!-- As part of publishing, ensure the JS resources are freshly built in production mode --> | ||
| <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> | ||
| <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" /> | ||
| <!-- Include the newly-built files in the publish output, served as static files from wwwroot --> | ||
| <ItemGroup> | ||
| <DistFiles Include="$(SpaRoot)build\**" /> | ||
| <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)"> | ||
| <RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath> | ||
| <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
| <ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||
| </ResolvedFileToPublish> | ||
| </ItemGroup> | ||
| </Target> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.AspNetCore.HttpsPolicy; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
@@ -43,12 +42,6 @@ public void ConfigureServices(IServiceCollection services) | |
|
|
||
| services.AddControllersWithViews(); | ||
|
|
||
| // In production, the React files will be served from this directory | ||
| services.AddSpaStaticFiles(configuration => | ||
| { | ||
| configuration.RootPath = "ClientApp/build"; | ||
| }); | ||
|
|
||
| services.AddEasyQuery() | ||
| .UseSqlManager() | ||
| .AddDefaultExporters() | ||
|
|
@@ -78,10 +71,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
| app.UseCors("AllowAllPolicy"); | ||
|
|
||
| app.UseHttpsRedirection(); | ||
| // In production, prebuilt SPA assets are copied into wwwroot by the | ||
| // PublishRunWebpack target and served via the default static-files middleware. | ||
| app.UseStaticFiles(); | ||
| if (!env.IsDevelopment()) { | ||
| app.UseSpaStaticFiles(); | ||
| } | ||
|
|
||
| app.UseRouting(); | ||
|
|
||
|
|
@@ -103,15 +95,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
| endpoints.MapControllerRoute( | ||
| name: "default", | ||
| pattern: "{controller}/{action=Index}/{id?}"); | ||
| }); | ||
|
|
||
| app.UseSpa(spa => | ||
| { | ||
| spa.Options.SourcePath = "ClientApp"; | ||
|
|
||
| if (env.IsDevelopment()) { | ||
| spa.UseReactDevelopmentServer(npmScript: "start"); | ||
| } | ||
| // SPA fallback: serve the prebuilt index.html for client-side routes in production. | ||
| // In Development the SPA is launched via Microsoft.AspNetCore.SpaProxy using the | ||
| // SpaProxyServerUrl/SpaProxyLaunchCommand MSBuild properties from the .csproj. | ||
| endpoints.MapFallbackToFile("index.html"); | ||
|
Comment on lines
+99
to
+102
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Missing client-side proxy configuration breaks API calls in development mode The migration from With SpaProxy, the browser is redirected to the React dev server directly (localhost:3000). Relative API URLs now resolve to localhost:3000 instead of the ASP.NET backend at localhost:5001, causing all API requests to fail. Other samples in this repo that use SpaProxy include client-side proxy configThe Vue3 example has Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acknowledged — the analysis is correct, this is a real functional gap. I'm intentionally not fixing it in this PR for two reasons:
@tobydrinkall — happy to send a follow-up PR for just |
||
| }); | ||
|
|
||
| //Init demo database (if necessary) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.