Skip to content

Commit

Permalink
Redirect the new React Application URL
Browse files Browse the repository at this point in the history
  • Loading branch information
AmielCyber committed Sep 15, 2023
1 parent a323c26 commit 14f5a3e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions PetSearch.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.OpenApi.Models;
Expand All @@ -14,7 +15,7 @@
const string petFinderTokenUrl = "https://api.petfinder.com/v2/oauth2/token";
const string mapBoxUrl = "https://api.mapbox.com/geocoding/v5/mapbox.places/";
const string allowReactApplication = "AllowReactApplication";
const string allowLocalDevelopment = "AllowLocalDevelopment";
const string allowLocalClientDevelopment = "AllowLocalClientDevelopment";

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

Expand All @@ -26,13 +27,13 @@
opts.SwaggerDoc("v1", new OpenApiInfo()
{
Title = "Pet Search",
Description = "An API to search available pets around a local area.",
Description = "An ASP.NET Core Web API for searching available pets within a local area.",
Version = "1.0",
Contact = new OpenApiContact
{
Name = "Amiel",
Url = new Uri("https://github.com/AmielCyber")
}
},
});
var file = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
opts.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, file));
Expand All @@ -56,7 +57,7 @@
.AllowCredentials();
}
);
options.AddPolicy(name: allowLocalDevelopment,
options.AddPolicy(name: allowLocalClientDevelopment,
policy =>
{
policy.WithOrigins("http://localhost:5173")
Expand Down Expand Up @@ -109,7 +110,7 @@
app.UseRouting(); // Move default middleware below the client-app middleware to short-circuit client-app routes.
if (app.Environment.IsDevelopment()) // Use cors configuration to develop with our client app.
{
app.UseCors(allowLocalDevelopment);
app.UseCors(allowLocalClientDevelopment);
}

if (app.Environment.IsProduction())
Expand All @@ -121,6 +122,12 @@
RouteGroupBuilder petsApi = app.MapGroup("/api/pets").WithParameterValidation();
RouteGroupBuilder locationApi = app.MapGroup("/api/location").WithParameterValidation();

if (app.Environment.IsProduction())
{
// Redirect user to the new React application URL as our server does not serve React files anymore.
app.MapGet("/", [ApiExplorerSettings(IgnoreApi = true)]() =>
Results.Redirect("https://pet-search-react.netlify.app", true));
}
// Register endpoints with their handlers.
petsApi.MapGet("/", PetHandler.GetPets).WithName("GetPets").WithOpenApi(o =>
{
Expand Down

0 comments on commit 14f5a3e

Please sign in to comment.