Skip to content

Commit

Permalink
Multiple providers and dynamic configuration (#76)
Browse files Browse the repository at this point in the history
* .

* cleanup
  • Loading branch information
mariuszkochanowski authored and madskristensen committed Mar 16, 2018
1 parent 23d9b62 commit e3e169e
Show file tree
Hide file tree
Showing 31 changed files with 974 additions and 12 deletions.
12 changes: 12 additions & 0 deletions WebOptimizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebOptimizer.Core.Test", "t
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebOptimizer.Core.Sample", "sample\WebOptimizer.Core.Sample.csproj", "{478357DE-07B8-443D-B430-E2390F74B060}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebOptimizer.Core.Sample2", "sample2\WebOptimizer.Core.Sample2\WebOptimizer.Core.Sample2.csproj", "{885AD8B7-1843-4579-8C28-E127B4A7CF68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebOptimizer.Core.Sample2.Lib", "sample2\WebOptimizer.Core.Sample2.Lib\WebOptimizer.Core.Sample2.Lib.csproj", "{F93B1ADA-6BF1-4BA3-9E88-2C5D84D81AD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,6 +38,14 @@ Global
{478357DE-07B8-443D-B430-E2390F74B060}.Debug|Any CPU.Build.0 = Debug|Any CPU
{478357DE-07B8-443D-B430-E2390F74B060}.Release|Any CPU.ActiveCfg = Release|Any CPU
{478357DE-07B8-443D-B430-E2390F74B060}.Release|Any CPU.Build.0 = Release|Any CPU
{885AD8B7-1843-4579-8C28-E127B4A7CF68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{885AD8B7-1843-4579-8C28-E127B4A7CF68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{885AD8B7-1843-4579-8C28-E127B4A7CF68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{885AD8B7-1843-4579-8C28-E127B4A7CF68}.Release|Any CPU.Build.0 = Release|Any CPU
{F93B1ADA-6BF1-4BA3-9E88-2C5D84D81AD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F93B1ADA-6BF1-4BA3-9E88-2C5D84D81AD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F93B1ADA-6BF1-4BA3-9E88-2C5D84D81AD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F93B1ADA-6BF1-4BA3-9E88-2C5D84D81AD8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion sample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:1557/",
"applicationUrl": "http://localhost:63698/",
"sslPort": 0
}
},
Expand Down
12 changes: 12 additions & 0 deletions sample2/WebOptimizer.Core.Sample2.Lib/AssemblyTools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Reflection;

namespace WebOptimizer.Core.Sample2.Lib
{
public class AssemblyTools
{
public static Assembly GetCurrentAssembly()
{
return typeof(AssemblyTools).Assembly;
}
}
}
7 changes: 7 additions & 0 deletions sample2/WebOptimizer.Core.Sample2.Lib/EmbeddedScript1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function (innerhtml) {
var content = document.getElementById("content"),
div = document.createElement("div");

div.innerHTML = innerhtml;
content.appendChild(div);
})('/EmbeddedResourcesScripts/EmbeddedScript1.js loaded');
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function (innerhtml) {
var content = document.getElementById("content"),
div = document.createElement("div");

div.innerHTML = innerhtml;
content.appendChild(div);
})('/EmbeddedResourcesScripts/Scripts/EmbeddedScript2.js loaded');
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>


<ItemGroup>
<None Remove="Scripts\EmbeddedScript2.js" />
<None Remove="EmbeddedScript1.js" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Scripts\EmbeddedScript2.js" />
<EmbeddedResource Include="EmbeddedScript1.js" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using WebOptimizer.Core.Sample2.Models;

namespace WebOptimizer.Core.Sample2.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}


public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
11 changes: 11 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace WebOptimizer.Core.Sample2.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
25 changes: 25 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace WebOptimizer.Core.Sample2
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
27 changes: 27 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61838/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebOptimizer.Core.Sample2": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:62609/"
}
}
}
7 changes: 7 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Scripts1/Script1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function (innerhtml) {
var content = document.getElementById("content"),
div = document.createElement("div");

div.innerHTML = innerhtml;
content.appendChild(div);
})('/Scripts1/Script1.js loaded');
7 changes: 7 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Scripts2/Script2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function (innerhtml) {
var content = document.getElementById("content"),
div = document.createElement("div");

div.innerHTML = innerhtml;
content.appendChild(div);
})('/Scripts2/Script2.js loaded');
83 changes: 83 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;

namespace WebOptimizer.Core.Sample2
{
public class Startup
{
public IConfiguration Configuration { get; }
public IHostingEnvironment HostingEnvironment { get; }

public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
{
Configuration = configuration;
HostingEnvironment = hostingEnvironment;
}


// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();


var cssSettings = new CssBundlingSettings();
var codeSettings = new CodeBundlingSettings
{
Minify = true,
};

services.AddWebOptimizer(HostingEnvironment, cssSettings, codeSettings);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}

const string scriptsPath1 = "Scripts1";
const string scriptsPath2 = "Scripts2";

var currentDirectory = Directory.GetCurrentDirectory();
app.UseWebOptimizer(HostingEnvironment, new[]
{
new FileProviderOptions
{
RequestPath = "/" + scriptsPath1,
FileProvider = new PhysicalFileProvider(Path.Combine(currentDirectory, scriptsPath1))
},
new FileProviderOptions
{
RequestPath = "/" + scriptsPath2,
FileProvider = new PhysicalFileProvider(Path.Combine(currentDirectory, scriptsPath2))
},
new FileProviderOptions
{
RequestPath = "/EmbeddedResourcesScripts",
FileProvider = new EmbeddedFileProvider(Lib.AssemblyTools.GetCurrentAssembly()),
}
});

app.UseStaticFiles();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
19 changes: 19 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@{
ViewData["Title"] = "Home Page";
}

<div id="content">

</div>

<script type="text/javascript" src="~/Scripts1/Script1.js" asp-append-version="true" asp-bundle-key="bundle1"></script>

<script type="text/javascript" src="~/Scripts2/Script2.js" asp-append-version="true" asp-bundle-key="bundle1"></script>

<script type="text/javascript" src="~/js/Script3.js" asp-append-version="true" asp-bundle-key="bundle1"></script>

<script type="text/javascript" src="~/EmbeddedResourcesScripts/EmbeddedScript1.js" asp-append-version="true" asp-bundle-key="bundle1"></script>

<script type="text/javascript" src="~/EmbeddedResourcesScripts/Scripts/EmbeddedScript2.js" asp-append-version="true" asp-bundle-key="bundle1"></script>

<script type="text/javascript" asp-bundle-dest-key="bundle1"></script>
22 changes: 22 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>
14 changes: 14 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebOptimizer.Core.Sample2</title>
</head>
<body>

@RenderBody()


</body>
</html>
7 changes: 7 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@using WebOptimizer.Core.Sample2
@using WebOptimizer.Core.Sample2.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.LinkTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.ScriptTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper WebOptimizer.TagHelpersDynamic.*, WebOptimizer.Core
3 changes: 3 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
20 changes: 20 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/WebOptimizer.Core.Sample2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\WebOptimizer.Core\WebOptimizer.Core.csproj" />
<ProjectReference Include="..\WebOptimizer.Core.Sample2.Lib\WebOptimizer.Core.Sample2.Lib.csproj" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
13 changes: 13 additions & 0 deletions sample2/WebOptimizer.Core.Sample2/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"webOptimizer": {
"enableCaching": true,
"enableTagHelperBundling": true
//"cdnUrl": "https://my-cdn.com/"
}
}
Loading

0 comments on commit e3e169e

Please sign in to comment.