Exemple #1
0
 public async Task Invoke(HttpContext context)
 {
     // Ensure Web-App is started
     if (!exeHandler.Started)
     {
         exeHandler.Start();
     }
     if (!exeHandler.StartFailed)
     {
         // Create Source
         var targetUri = BuildTargetUri(context.Request);
         if (targetUri != null)
         {
             // Create Request for target & send it
             var targetRequestMessage = CreateTargetMessage(context, targetUri);
             Console.WriteLine(targetRequestMessage.Headers.ToString());
             using (var responseMessage = await GetTargetResponse(context, targetRequestMessage))
             {
                 context.Response.StatusCode = (int)responseMessage.StatusCode;
                 CopyFromTargetResponseHeaders(context, responseMessage);
                 await responseMessage.Content.CopyToAsync(context.Response.Body);
             }
             return;
         }
     }
     else
     {
         throw new Exception("Start of WebApp Executable failed!");
     }
     await nextMiddleware(context);
 }
Exemple #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime)
        {
            // Register Shutdown Event
            applicationLifetime.ApplicationStopping.Register(OnShutdown);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Configure & Start web app process handler
            exeHandler = new ExecutableHandler(
                config.GetValue <string>("appSettings:appProcessName"),
                config.GetValue <string>("appSettings:appProcessArgs"),
                config.GetValue <int>("appSettings:appProcessPort"),
                ParseEnvConfig(config.GetValue <string>("appSettings:appProcessEnv")));

            exeHandler.Start();

            // Configure reverse proxy
            app.UseReverseProxy(new ReverseProxyOptions {
                BaseUrl           = $"http://localhost:" + config.GetValue <int>("appSettings:appProcessPort"),
                ExecutableHandler = exeHandler
            });
        }