Skip to content

Commit

Permalink
Update AGS.Resource.Proxy using DotNet6.
Browse files Browse the repository at this point in the history
+ Trimed out unused webpage under wwwroot and Page Cshtml
+ Trimed Path of ~/proxy.ashx
+ Trimed basic layout to redirect to ~/proxy.ashx
  • Loading branch information
abhaymenon committed Mar 2, 2022
1 parent 7e48774 commit 1e8f431
Show file tree
Hide file tree
Showing 56 changed files with 54 additions and 24,115 deletions.
10 changes: 5 additions & 5 deletions Ags.ResourceProxy.Core.Tests/Ags.ResourceProxy.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Moq" Version="4.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.1" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.17.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions Ags.ResourceProxy.Core/Ags.ResourceProxy.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://mit-license.org/</PackageLicenseUrl>
Expand All @@ -16,10 +16,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions Ags.ResourceProxy.Core/Proxy/ProxyServerMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ IMemoryCache memoryCache
public async Task Invoke(HttpContext context) {
var endRequest = false;

if (!context.Request.QueryString.HasValue)
{
await context.Response.WriteAsync(CreateEmptyExceptionResponse());
return;
}

if (context.Request.QueryString.HasValue && context.Request.QueryString.ToString().ToLower() == "?ping") {
await context.Response.WriteAsync(CreatePingResponse());
return;
Expand Down Expand Up @@ -151,5 +157,18 @@ private string CreatePingResponse() {
return JsonConvert.SerializeObject(pingResponse);
}

private string CreateEmptyExceptionResponse()
{
var errorResponse = new
{
error = new
{
code = HttpStatusCode.BadRequest,
message = "This proxy does not support empty parameters."
}
};
return JsonConvert.SerializeObject(errorResponse);
}

}
}
16 changes: 8 additions & 8 deletions Ags.ResourceProxy.Web/Ags.ResourceProxy.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<Content Remove="proxy.config.json" />
</ItemGroup>

<ItemGroup>
<None Include="proxy.config.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.3.310801">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Ags.ResourceProxy.Core\Ags.ResourceProxy.Core.csproj" />
</ItemGroup>

</Project>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project>
9 changes: 0 additions & 9 deletions Ags.ResourceProxy.Web/Pages/About.cshtml

This file was deleted.

18 changes: 0 additions & 18 deletions Ags.ResourceProxy.Web/Pages/About.cshtml.cs

This file was deleted.

19 changes: 0 additions & 19 deletions Ags.ResourceProxy.Web/Pages/Contact.cshtml

This file was deleted.

18 changes: 0 additions & 18 deletions Ags.ResourceProxy.Web/Pages/Contact.cshtml.cs

This file was deleted.

23 changes: 0 additions & 23 deletions Ags.ResourceProxy.Web/Pages/Error.cshtml

This file was deleted.

23 changes: 0 additions & 23 deletions Ags.ResourceProxy.Web/Pages/Error.cshtml.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Ags.ResourceProxy.Web/Pages/Privacy.cshtml

This file was deleted.

16 changes: 0 additions & 16 deletions Ags.ResourceProxy.Web/Pages/Privacy.cshtml.cs

This file was deleted.

68 changes: 3 additions & 65 deletions Ags.ResourceProxy.Web/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,10 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Ags.ResourceProxy.Web</title>

<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment exclude="Development">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
<meta http-equiv = "refresh" content = "2; url = proxy.ashx"/>
<title>Resource Proxy</title>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a asp-page="/Index" class="navbar-brand">Ags.ResourceProxy.Web</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a asp-page="/Index">Home</a></li>
<li><a asp-page="/About">About</a></li>
<li><a asp-page="/Contact">Contact</a></li>
</ul>
</div>
</div>
</nav>

<partial name="_CookieConsentPartial" />

<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; 2018 - Ags.ResourceProxy.Web</p>
</footer>
</div>

<environment include="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
</environment>
<environment exclude="Development">
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery"
crossorigin="anonymous"
integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
crossorigin="anonymous"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
</script>
<script src="~/js/site.min.js" asp-append-version="true"></script>
</environment>

@RenderSection("Scripts", required: false)
@{ RenderBody(); }
</body>
</html>
14 changes: 4 additions & 10 deletions Ags.ResourceProxy.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Ags.ResourceProxy.Web {
public class Program {
namespace Ags.ResourceProxy.Web
{
public class Program {
public static void Main(string[] args) {
CreateWebHostBuilder(args).Build().Run();
}
Expand Down
19 changes: 9 additions & 10 deletions Ags.ResourceProxy.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using System.Linq;
using System.Net.Http;
using Ags.ResourceProxy.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Net.Http;

namespace Ags.ResourceProxy.Web {
public class Startup {
namespace Ags.ResourceProxy.Web
{
public class Startup {
public Startup(IConfiguration configuration) {
Configuration = configuration;
}
Expand All @@ -36,9 +36,8 @@ public void ConfigureServices(IServiceCollection services) {
};
});
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Latest);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
Expand All @@ -54,7 +53,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
app.UseCookiePolicy();

app.UseWhen(context => {
return context.Request.Path.Value.ToLower().StartsWith(@"/proxy/proxy.ashx", StringComparison.OrdinalIgnoreCase);
return context.Request.Path.Value.ToLower().StartsWith(@"/proxy.ashx", StringComparison.OrdinalIgnoreCase);
//&& context.User.Identity.IsAuthenticated; // Add this back in to keep unauthenticated users from utilzing the proxy.
},
builder =>
Expand Down
Loading

0 comments on commit 1e8f431

Please sign in to comment.