diff --git a/client/public/index.html b/client/public/index.html index aa069f2..fbdddf3 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -5,39 +5,10 @@ - - - - - React App - -
- +
diff --git a/client/src/App.js b/client/src/App.js index a0f61d0..4084a85 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -51,7 +51,14 @@ export default class App extends Component { } async populateWeatherData() { - const response = await fetch('https://criminalminds-server.azurewebsites.net/weatherforecast'); + + const url = '/api/seasons'; + + if (process.env.NODE_ENV == 'production') { + url = 'https://criminalminds-server.azurewebsites.net' + url; + } + + const response = await fetch(url); const data = await response.json(); this.setState({ forecasts: data, loading: false }); } diff --git a/client/src/setupProxy.js b/client/src/setupProxy.js index 72f4c46..8a899ab 100644 --- a/client/src/setupProxy.js +++ b/client/src/setupProxy.js @@ -1,7 +1,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware'); const context = [ - "/weatherforecast", + '/api/seasons' ]; module.exports = function (app) { diff --git a/server/Controllers/WeatherForecastController.cs b/server/Controllers/WeatherForecastController.cs deleted file mode 100644 index c3a25d4..0000000 --- a/server/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace server.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} \ No newline at end of file diff --git a/server/Program.cs b/server/Program.cs index b83fd9b..67e2101 100644 --- a/server/Program.cs +++ b/server/Program.cs @@ -1,5 +1,20 @@ +using Microsoft.Extensions.Options; +using MongoDB.Driver; +using server.Persistence; +using server.Persistence.Repositories; + var builder = WebApplication.CreateBuilder(args); +builder.Services.Configure( + builder.Configuration.GetSection("MongoDBSettings")); + +builder.Services.AddSingleton(sp => + sp.GetRequiredService>().Value); + +builder.Services.AddSingleton(); + +builder.Services.AddScoped(); + builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); @@ -7,11 +22,9 @@ builder.Services.AddSwaggerGen(); var app = builder.Build(); -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} +app.UseSwagger(); + +app.UseSwaggerUI(); app.UseHttpsRedirection(); diff --git a/server/WeatherForecast.cs b/server/WeatherForecast.cs deleted file mode 100644 index 1b7802b..0000000 --- a/server/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace server -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} \ No newline at end of file diff --git a/server/server.csproj b/server/server.csproj index 60bf9ea..675eba3 100644 --- a/server/server.csproj +++ b/server/server.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,8 @@ - + +