Skip to content

Commit

Permalink
1.0.5 (#11)
Browse files Browse the repository at this point in the history
* add webvisor

* remove ya metrica in dev env

* disable calc button if there is only one person

* remove unused code

* add tests

* #6 fix backend error

* fix #6

* #10 add healthcheck

* add production config, please close #10

* fix healtcheck

* add serilog and sentry, #9, #8; webvison 2;

* update release version for Sentry

* update manifest.json for mobile version

* close #9; close #8;
  • Loading branch information
framebassman committed Feb 3, 2019
1 parent c1c5efe commit 93b9d29
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Izzy.Web/Client/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "Izzy",
"name": "Izzy - рассчитай, сколько тебе должны после вечеринки",
"icons": [
{
"src": "favicon.ico",
Expand All @@ -10,6 +10,6 @@
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"theme_color": "#8fd5eb",
"background_color": "#ffffff"
}
11 changes: 9 additions & 2 deletions Izzy.Web/Client/src/YandexMetrica.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ export const YandexMetrica = (props: YandexMetricaProps) => {
if (isProd()) {
return (
<YMInitializer
accounts={props.accounts}
options={{webvisor: true}}
accounts={props.accounts}
options={{
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: true,
trackHash: true,
}}
version="2"
/>
)
} else {
Expand Down
4 changes: 3 additions & 1 deletion Izzy.Web/Controllers/CalculatorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Izzy.Web.Model;
using Newtonsoft.Json;

namespace Izzy.Web.Controllers
{
Expand All @@ -20,16 +21,17 @@ public CalculatorController(ILogger<CalculatorController> logger)
public IActionResult Calculate([FromBody] IEnumerable<Person> persons)
{
if (ModelState.IsValid) {
this._logger.LogInformation("Persons was: {persons}", persons);
return new OkObjectResult(
new Receipt(persons)
.Transfers()
);
} else {
this._logger.LogInformation("Invalid request: {persons}", persons);
return new BadRequestObjectResult(
"Name should have string type, Roubles should have number type"
);
}

}
}
}
6 changes: 6 additions & 0 deletions Izzy.Web/Izzy.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Sentry" Version="1.1.2" />
<PackageReference Include="Sentry.AspNetCore" Version="1.1.2" />
<PackageReference Include="Sentry.Serilog" Version="1.1.2" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.2-dev-00028" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.1-dev-00925" />
<PackageReference Include="Serilog.Sinks.ColoredConsole" Version="3.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
33 changes: 33 additions & 0 deletions Izzy.Web/Middlewares/HealthCheckMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers;

namespace Izzy.Web.Middlewares
{
public class HealthCheckMiddleware
{
private const string _path = "/healthcheck";
private readonly RequestDelegate _next;

public HealthCheckMiddleware(RequestDelegate next)
{
_next = next;
}

public async Task Invoke(HttpContext context)
{
if (!context.Request.Path.Equals(_path, StringComparison.OrdinalIgnoreCase))
{
await _next(context);
}
else
{
context.Response.ContentType = "text/plain";
context.Response.StatusCode = 200;
context.Response.Headers.Add(HeaderNames.Connection, "close");
await context.Response.WriteAsync("OK");
}
}
}
}
5 changes: 5 additions & 0 deletions Izzy.Web/Model/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ public Person(String name, Decimal roubles)
this.Name = name;
this.Roubles = roubles;
}

public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
}
36 changes: 35 additions & 1 deletion Izzy.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
using System;
using System.IO;
using System.Net;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Sentry;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Compact;

namespace Izzy.Web
{
Expand All @@ -13,6 +21,32 @@ public static void Main(string[] args)
private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:5000");
.UseUrls("http://0.0.0.0:5000")
.UseSerilog((h, c) =>
c.Enrich.FromLogContext()
.MinimumLevel.Warning()
.MinimumLevel.Override("Izzy.Web", LogEventLevel.Information)
.WriteTo.ColoredConsole()
.WriteTo.Sentry(s =>
{
s.MinimumBreadcrumbLevel = LogEventLevel.Debug;
s.MinimumEventLevel = LogEventLevel.Error;
})
)
.UseSentry(options =>
{
options.Release = "1.0.5";
options.Environment = CurrentEnv();
options.MaxQueueItems = 100;
options.ShutdownTimeout = TimeSpan.FromSeconds(5);
options.DecompressionMethods = DecompressionMethods.None;
})
;

private static String CurrentEnv()
{
return Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
}
}
}
2 changes: 2 additions & 0 deletions Izzy.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Izzy.Web.Middlewares;

namespace Izzy.Web
{
Expand Down Expand Up @@ -40,6 +41,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseHsts();
}

app.UseMiddleware<HealthCheckMiddleware>();
app.UseStaticFiles();
app.UseSpaStaticFiles();

Expand Down
2 changes: 1 addition & 1 deletion Izzy.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
Expand Down
6 changes: 5 additions & 1 deletion Izzy.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"Default": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Sentry": {
"Dsn": "https://[email protected]/1385588",
"IncludeRequestPayload": true
}
}

0 comments on commit 93b9d29

Please sign in to comment.