/ Startup.cs
Startup.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using Microsoft.AspNetCore.Builder; 6 using Microsoft.AspNetCore.Hosting; 7 using Microsoft.AspNetCore.Http; 8 using Microsoft.Extensions.DependencyInjection; 9 using Microsoft.Extensions.Hosting; 10 using Tyle.Nft.Api; 11 12 namespace GrpcService1 13 { 14 public class Startup 15 { 16 17 // This method gets called by the runtime. Use this method to add services to the container. 18 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 19 public void ConfigureServices(IServiceCollection services) 20 { 21 services.AddCors(options => 22 { 23 options.AddDefaultPolicy( 24 builder => 25 { 26 builder.WithOrigins("*") 27 .AllowAnyHeader() 28 .AllowAnyMethod(); 29 }); 30 }); 31 services.AddMvc().AddNewtonsoftJson(); 32 //services.AddControllers(); 33 services.AddScoped<Token1Controller>(); 34 services.AddGrpc(); 35 } 36 37 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 38 public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 39 { 40 if (env.IsDevelopment()) 41 { 42 app.UseDeveloperExceptionPage(); 43 } 44 45 app.UseRouting(); 46 47 app.UseCors(); 48 49 app.UseAuthorization(); 50 51 app.UseEndpoints(endpoints => 52 { 53 endpoints.MapGrpcService<CubeService>(); 54 55 endpoints.MapGet("/", async context => 56 { 57 await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); 58 }); 59 60 endpoints.MapControllers(); 61 62 }); 63 } 64 } 65 }