Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // Change the Root Path of the AuthServer
            app.UsePathBase($"/{SERVICE_ENDPOINT_REWRITE}");

            // Initialize our Databases
            try
            {
                AuthServerDatabaseConfiguration databaseConfig = new AuthServerDatabaseConfiguration(Configuration, app);
                databaseConfig.InitializeDatabase(app);
            }
            catch (Exception e)
            {
                _logger.LogWarning("Caught exception when initializing DB: {Exception}", e);
            }

            // Configure our Error Pages
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            // Enable Swagger Middleware
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"/{SERVICE_ENDPOINT_REWRITE}/swagger/v1/swagger.json", "Auth Server API");
            });

            // Enable CORS
            // app.UseCors(Startup.CORS_POLICY);
            // app.UseCors(
            //     options => options.AllowAnyOrigin()//.WithOrigins("http://localhost:3000")
            //     .AllowAnyMethod()
            //     .AllowAnyHeader()
            // );

            _logger.LogInformation("Waiting for rabbitmq...");
            // Block until the rabbitmq panel is online
            NetworkingHelpers.WaitForOk(new Uri("http://rabbitmq:15672")).Wait();
            _logger.LogInformation("rabbitmq is ready");

            // Setup our pipeline to use Static Files...
            app.UseStaticFiles();

            // Load in IdentityServer Middleware
            app.UseIdentityServer();

            // Setup MVC with a Default Route
            app.UseMvcWithDefaultRoute();
            //app.UseMvc();
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // Change the Root Path of the Profile
            app.UsePathBase($"/{SERVICE_ENDPOINT_REWRITE}");

            // Initialize our Databases
            try
            {
                ProfileServiceDatabaseConfiguration databaseConfig = new ProfileServiceDatabaseConfiguration(Configuration, app);
                databaseConfig.InitializeDatabase(app);
            }
            catch (Exception) { }

            // Configure our Error Pages
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            // Setup http to https redirection
            app.UseHttpsRedirection();

            // Enable Swagger Middleware
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"/{SERVICE_ENDPOINT_REWRITE}/swagger/v1/swagger.json", "Profile Service API");
            });

            _logger.LogInformation("Waiting for rabbitmq...");
            // Block until the rabbitmq panel is online
            NetworkingHelpers.WaitForOk(new Uri("http://rabbitmq:15672")).Wait();
            _logger.LogInformation("rabbitmq is ready");

            // Setup MVC with a Default Route
            //app.UseMvcWithDefaultRoute();
            app.UseMvc();
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Cors
            // services.AddCors(options =>
            // {
            //     options.AddPolicy(Startup.CORS_POLICY, policy =>
            //     {
            //         policy
            //             .AllowAnyOrigin()
            //             .AllowAnyHeader()
            //             .AllowAnyMethod();
            //     });
            // });
            // services.AddCors();

            // Add MVCCore
            services.AddMvcCore()
            .AddApiExplorer()
            .AddAuthorization()
            .AddJsonFormatters()
            // .AddCors()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // Setup Authentication
            services.AddAuthentication("Bearer")
            .AddJwtBearer("Bearer", options =>
            {
                options.Authority            = "http://localhost:5001";
                options.RequireHttpsMetadata = false;
                options.Audience             = "api1";
            });

            // Configure Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info {
                    Title = "API Gateway API", Version = "v1"
                });
            });

            // Configure RabbitMq
            services.AddRawRabbit(options =>
            {
                options.SetBasePath(Environment.ContentRootPath)
                .AddJsonFile("rawrabbit.json")
                .AddEnvironmentVariables("RawRabbit:");
            });

            _logger.LogInformation("Waiting for rabbitmq...");
            // Block until the rabbitmq panel is online (which should mean the queue is ready)
            NetworkingHelpers.WaitForOk(new Uri("http://rabbitmq:15672")).Wait();
            _logger.LogInformation("rabbitmq is ready");

            // Add the QueueHelpers class to the DI as a singleton
            services.AddSingleton <QueueHelpers>();

            // Additional Configuration
            services.AddHttpContextAccessor();
            services.AddSingleton <ContextServiceLocator>();
            GraphQLConfiguration.Configure(services);

            // Build the GraphQL Schema
            var sp = services.BuildServiceProvider();

            services.AddSingleton <ISchema>(new APIGatewaySchema(new FuncDependencyResolver(type => sp.GetService(type))));
        }