Skip to content

Commit 574be94

Browse files
author
Bo Clifton
committed
Add project files.
1 parent b53a705 commit 574be94

15 files changed

+295
-0
lines changed

ClientApp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 72a355b9ad81b4227670df030a0bcc81eda671d8
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Logging;
7+
using NetCoreWebApiWithVue.Models;
8+
9+
namespace NetCoreWebApiWithVue.Controllers
10+
{
11+
[ApiController]
12+
[Route("api/[controller]")]
13+
public class WeatherForecastController : ControllerBase
14+
{
15+
private static readonly string[] Summaries = new[]
16+
{
17+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
18+
};
19+
20+
private readonly ILogger<WeatherForecastController> _logger;
21+
22+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
23+
{
24+
_logger = logger;
25+
}
26+
27+
[HttpGet]
28+
public IEnumerable<WeatherForecast> Get()
29+
{
30+
var rng = new Random();
31+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
32+
{
33+
Date = DateTime.Now.AddDays(index),
34+
TemperatureC = rng.Next(-20, 55),
35+
Summary = Summaries[rng.Next(Summaries.Length)]
36+
})
37+
.ToArray();
38+
}
39+
}
40+
}

Models/WeatherForecast.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace NetCoreWebApiWithVue.Models
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}

NetCoreWebApiWithVue.csproj

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<SpaRoot>client\</SpaRoot>
9+
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<!-- Don't publish the SPA source files, but do show them in the project files list -->
14+
<Content Remove="$(SpaRoot)**" />
15+
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Folder Include="wwwroot\" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="vueclimiddleware" Version="3.1.1" />
24+
</ItemGroup>
25+
26+
27+
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build">
28+
<!-- Build Target: Ensure Node.js is installed -->
29+
<Exec Command="node --version" ContinueOnError="true">
30+
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
31+
</Exec>
32+
<Exec Command="npm --version" ContinueOnError="true">
33+
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
34+
</Exec>
35+
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js and npm are 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." />
36+
</Target>
37+
38+
<Target Name="EnsureNodeModulesInstalled" BeforeTargets="Build" Inputs="package.json" Outputs="packages-lock.json" Condition="!Exists('$(SpaRoot)node_modules')">
39+
<!-- Build Target: Restore NPM packages using npm -->
40+
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
41+
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
42+
</Target>
43+
44+
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
45+
<!-- Build Target: Run webpack dist build -->
46+
<Message Importance="high" Text="Running npm build..." />
47+
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
48+
49+
<!-- Include the newly-built files in the publish output -->
50+
<ItemGroup>
51+
<DistFiles Include="$(SpaRoot)dist\**" />
52+
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
53+
<RelativePath>%(DistFiles.Identity)</RelativePath>
54+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
55+
<ExcludeFromSingleFile>True</ExcludeFromSingleFile>
56+
</ResolvedFileToPublish>
57+
</ItemGroup>
58+
</Target>
59+
60+
</Project>

NetCoreWebApiWithVue.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30104.148
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreWebApiWithVue", "NetCoreWebApiWithVue.csproj", "{9FABEB40-0668-4EFC-A8E9-1BF4156AC45F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9FABEB40-0668-4EFC-A8E9-1BF4156AC45F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9FABEB40-0668-4EFC-A8E9-1BF4156AC45F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9FABEB40-0668-4EFC-A8E9-1BF4156AC45F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9FABEB40-0668-4EFC-A8E9-1BF4156AC45F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {A9C3BA90-4F56-4923-8323-CF29560CA1CF}
24+
EndGlobalSection
25+
EndGlobal

Program.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace NetCoreWebApiWithVue
11+
{
12+
public class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
CreateHostBuilder(args).Build().Run();
17+
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder =>
22+
{
23+
webBuilder.UseStartup<Startup>();
24+
});
25+
}
26+
}

Properties/launchSettings.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:58787",
7+
"sslPort": 0
8+
}
9+
},
10+
"$schema": "http://json.schemastore.org/launchsettings.json",
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"NetCoreWebApiWithVue": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
26+
}
27+
}
28+
}

Startup.cs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.SpaServices;
4+
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Hosting;
7+
using VueCliMiddleware;
8+
9+
namespace NetCoreWebApiWithVue
10+
{
11+
public class Startup
12+
{
13+
public Startup(IConfiguration configuration)
14+
{
15+
Configuration = configuration;
16+
}
17+
18+
public IConfiguration Configuration { get; }
19+
20+
// This method gets called by the runtime. Use this method to add services to the container.
21+
public void ConfigureServices(IServiceCollection services)
22+
{
23+
// NOTE: PRODUCTION Ensure this is the same path that is specified in your webpack output
24+
services.AddSpaStaticFiles(opt => opt.RootPath = "ClientApp/dist");
25+
services.AddControllers();
26+
}
27+
28+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
29+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
30+
{
31+
if (env.IsDevelopment())
32+
{
33+
app.UseDeveloperExceptionPage();
34+
}
35+
36+
// NOTE: this is optional, it adds HTTPS to Kestrel
37+
app.UseHttpsRedirection();
38+
39+
// NOTE: PRODUCTION uses webpack static files
40+
app.UseSpaStaticFiles();
41+
42+
app.UseRouting();
43+
44+
app.UseAuthorization();
45+
46+
app.UseEndpoints(endpoints =>
47+
{
48+
endpoints.MapControllers();
49+
50+
// NOTE: VueCliProxy is meant for developement and hot module reload
51+
// NOTE: SSR has not been tested
52+
// Production systems should only need the UseSpaStaticFiles() (above)
53+
// You could wrap this proxy in either
54+
// if (System.Diagnostics.Debugger.IsAttached)
55+
// or a preprocessor such as #if DEBUG
56+
endpoints.MapToVueCliProxy(
57+
"{*path}",
58+
new SpaOptions { SourcePath = "ClientApp" },
59+
npmScript: (System.Diagnostics.Debugger.IsAttached) ? "serve" : null,
60+
regex: "Compiled successfully",
61+
forceKill: true
62+
);
63+
});
64+
}
65+
}
66+
}

VueCliSample.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

appsettings.Development.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}

appsettings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}

client

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 72a355b9ad81b4227670df030a0bcc81eda671d8

package-lock.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"scripts": {
3+
"serve": "cd ClientApp && vue-cli-service serve",
4+
"build": "cd ClientApp && vue-cli-service build",
5+
"lint": "cd ClientApp && vue-cli-service lint"
6+
}
7+
}

wwwroot/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)