public static IWebHostBuilder CreateWebHostBuilder(string[] args) { BuildConfiguration(args); var tethysConfig = TethysConfig.FromConfiguration(Configuration); var urls = tethysConfig.HttpPorts.Select(hp => "http://localhost:" + hp).ToArray(); return(WebHost.CreateDefaultBuilder(args) .UseConfiguration(Configuration) .UseStartup <Startup>() .UseSerilog() .UseUrls(urls)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddCors(options => options.AddPolicy(CorsPolicy, builder => { builder .AllowAnyMethod() .AllowAnyHeader() .AllowAnyOrigin() .AllowCredentials(); })); services.AddSignalR(options => options.EnableDetailedErrors = true); TethysConfig = TethysConfig.FromConfiguration(Configuration); services.AddSingleton <TethysConfig>(sp => TethysConfig); services.AddSingleton <TethysHub>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Tethys API", Version = "v1", Contact = new Contact { Name = "Click for dashboard", Url = _hasStaticFiles ? "./../ui/index.html" : "Not html files found. Verify you run tethys from it's base directory" }, }); c.DescribeAllEnumsAsStrings(); c.DescribeStringEnumsInCamelCase(); c.DescribeAllParametersInCamelCase(); c.OperationFilter <FileUploadOperation>(); // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetEntryAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } }); AddLiteDb(services, Configuration); services.AddTransient <IHttpCallService, HttpCallService>(); services.AddTransient <INotificationService, NotificationService>(); services.AddTransient <INotificationPublisher, NotificationPublisher>(); services.AddSingleton <IFileUploadManager, FileUploadManager>(); services.AddSingleton <IRequestResponseCoupleService, RequestResponseCoupleService>(); }
public static void RedirectRequests(HttpRequest request, TethysConfig tethysConfig) { //if tethys requests - continue if (!ShouldInterceptRequestByPath(request, tethysConfig.WebSocketSuffix)) { return; } request.HttpContext.Items[Consts.OriginalRequest] = new Request { Resource = request.Path, Query = request.QueryString.ToString(), HttpMethod = request.Method, Headers = request.Headers.ToDictionary(s => s.Key, s => s.Value.ToString()), Body = "Not parsed yet. see: RedirectRules" }; BuildRedirectLogic(tethysConfig, request); }
private static void BuildRedirectLogic(TethysConfig tethysConfig, HttpRequest request) { var isWebSocketRequest = tethysConfig .WebSocketSuffix .Any(wss => RequestStartsWithSegment(request, wss)); var path = isWebSocketRequest ? Consts.TethysWebSocketPath : Consts.HttpCallControllerRoute; if (isWebSocketRequest) { if (request.Path.Value.EndsWith(Consts.TethysWebSocketPathNegotiate, StringComparison.InvariantCultureIgnoreCase)) { path += Consts.TethysWebSocketPathNegotiate; } } else { request.Method = HttpMethods.Get; } request.Path = path; }