Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit 53c744f

Browse files
committed
Updated samples to reflect changes for AspNetCore 3.1
1 parent 7d4ede2 commit 53c744f

File tree

6 files changed

+76
-22
lines changed

6 files changed

+76
-22
lines changed

README.md

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,53 @@ First, be sure to switch Vue Cli or Quasar Cli to output distribution files to w
1919

2020
See [Migrating Asp.Net 2.2 to 3.0 Endpoint Routing](https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-2.2&tabs=visual-studio#update-routing-startup-code)
2121
```csharp
22-
// To use with EndpointRouting
22+
23+
24+
public class Startup {
25+
26+
public Startup(IConfiguration configuration)
27+
{
28+
Configuration = configuration;
29+
}
30+
31+
public IConfiguration Configuration { get; }
32+
33+
// This method gets called by the runtime. Use this method to add services to the container.
34+
public void ConfigureServices(IServiceCollection services)
35+
{
36+
// NOTE: PRODUCTION Ensure this is the same path that is specified in your webpack output
37+
services.AddSpaStaticFiles(opt => opt.RootPath = "ClientApp/dist");
38+
services.AddControllers();
39+
}
40+
41+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
42+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
43+
{
44+
// NOTE: PRODUCTION uses webpack static files
45+
app.UseSpaStaticFiles();
46+
47+
// To use with EndpointRouting
48+
app.UseRouting();
2349

2450
app.UseEndpoints(endpoints =>
2551
{
2652
endpoints.MapControllers();
2753

28-
// initialize vue cli middleware
29-
#if DEBUG
30-
if (System.Diagnostics.Debugger.IsAttached)
31-
endpoints.MapToVueCliProxy("{*path}", new SpaOptions { SourcePath = "ClientApp" }, "dev", regex: "Compiled successfully");
32-
else
33-
#endif
34-
// note: output of vue cli or quasar cli should be wwwroot
35-
endpoints.MapFallbackToFile("index.html");
54+
// NOTE: VueCliProxy is meant for developement and hot module reload
55+
// NOTE: SSR has not been tested
56+
// Production systems should only need the UseSpaStaticFiles() (above)
57+
// You could wrap this proxy in either
58+
// if (System.Diagnostics.Debugger.IsAttached)
59+
// or a preprocessor such as #if DEBUG
60+
endpoints.MapToVueCliProxy(
61+
"{*path}",
62+
new SpaOptions { SourcePath = "ClientApp" },
63+
npmScript: (System.Diagnostics.Debugger.IsAttached) ? "serve" : null,
64+
regex: "Compiled successfully",
65+
forceKill: true
66+
);
3667
});
68+
}
3769
```
3870

3971

@@ -55,10 +87,7 @@ See [Migrating Asp.Net 2.2 to 3.0 Endpoint Routing](https://docs.microsoft.com/e
5587
services.AddMvc(); // etc
5688
5789
// Need to register ISpaStaticFileProvider for UseSpaStaticFiles middleware to work
58-
services.AddSpaStaticFiles(configuration =>
59-
{
60-
configuration.RootPath = "ClientApp/dist";
61-
});
90+
services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; });
6291
}
6392

6493
public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env)

samples/QuasarCliSample/Properties/launchSettings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"QuasarCliSample": {
2020
"commandName": "Project",
2121
"launchBrowser": true,
22-
"launchUrl": "api/values",
2322
"environmentVariables": {
2423
"ASPNETCORE_ENVIRONMENT": "Development"
2524
},

samples/QuasarCliSample/Startup.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public Startup(IConfiguration configuration)
2828
// This method gets called by the runtime. Use this method to add services to the container.
2929
public void ConfigureServices(IServiceCollection services)
3030
{
31+
// NOTE: PRODUCTION Ensure this is the same path that is specified in your webpack output
3132
services.AddSpaStaticFiles(opt => opt.RootPath = "ClientApp/dist");
3233
services.AddControllers();
3334
}
@@ -40,6 +41,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4041
app.UseDeveloperExceptionPage();
4142
}
4243

44+
// NOTE: this is optional, it adds HTTPS to Kestrel
45+
app.UseHttpsRedirection();
46+
47+
// NOTE: PRODUCTION uses webpack static files
4348
app.UseSpaStaticFiles();
4449

4550
app.UseRouting();
@@ -50,13 +55,18 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5055
{
5156
endpoints.MapControllers();
5257

53-
// Note: only use vuecliproxy in development.
54-
// Production should use "UseSpaStaticFiles()" and the webpack dist
58+
// NOTE: VueCliProxy is meant for developement and hot module reload
59+
// NOTE: SSR has not been tested
60+
// Production systems should only need the UseSpaStaticFiles() (above)
61+
// You could wrap this proxy in either
62+
// if (System.Diagnostics.Debugger.IsAttached)
63+
// or a preprocessor such as #if DEBUG
5564
endpoints.MapToVueCliProxy(
5665
"{*path}",
5766
new SpaOptions { SourcePath = "ClientApp" },
58-
npmScript: (System.Diagnostics.Debugger.IsAttached) ? "serve" : null
59-
);
67+
npmScript: (System.Diagnostics.Debugger.IsAttached) ? "serve" : null,
68+
forceKill: true);
69+
6070
});
6171
}
6272
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// vue.config.js
2+
module.exports = {
3+
devServer: {
4+
progress: false
5+
}
6+
}

samples/VueCliSample/Properties/launchSettings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"VueCliSample": {
2020
"commandName": "Project",
2121
"launchBrowser": true,
22-
"launchUrl": "api/values",
2322
"environmentVariables": {
2423
"ASPNETCORE_ENVIRONMENT": "Development"
2524
},

samples/VueCliSample/Startup.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public Startup(IConfiguration configuration)
2727
// This method gets called by the runtime. Use this method to add services to the container.
2828
public void ConfigureServices(IServiceCollection services)
2929
{
30+
// NOTE: PRODUCTION Ensure this is the same path that is specified in your webpack output
31+
services.AddSpaStaticFiles(opt => opt.RootPath = "ClientApp/dist");
3032
services.AddControllers();
3133
}
3234

@@ -38,8 +40,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3840
app.UseDeveloperExceptionPage();
3941
}
4042

43+
// NOTE: this is optional, it adds HTTPS to Kestrel
4144
app.UseHttpsRedirection();
4245

46+
// NOTE: PRODUCTION uses webpack static files
47+
app.UseSpaStaticFiles();
48+
4349
app.UseRouting();
4450

4551
app.UseAuthorization();
@@ -48,13 +54,18 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4854
{
4955
endpoints.MapControllers();
5056

51-
// Note: only use vuecliproxy in development.
52-
// Production should use "UseSpaStaticFiles()" and the webpack dist
57+
// NOTE: VueCliProxy is meant for developement and hot module reload
58+
// NOTE: SSR has not been tested
59+
// Production systems should only need the UseSpaStaticFiles() (above)
60+
// You could wrap this proxy in either
61+
// if (System.Diagnostics.Debugger.IsAttached)
62+
// or a preprocessor such as #if DEBUG
5363
endpoints.MapToVueCliProxy(
5464
"{*path}",
5565
new SpaOptions { SourcePath = "ClientApp" },
5666
npmScript: (System.Diagnostics.Debugger.IsAttached) ? "serve" : null,
57-
regex: "Compiled successfully"
67+
regex: "Compiled successfully",
68+
forceKill: true
5869
);
5970
});
6071
}

0 commit comments

Comments
 (0)