private void InitializeHttpFunctions(IEnumerable <FunctionDescriptor> functions, HttpExtensionConfiguration httpConfig) { _router.ClearRoutes(); // TODO: FACAVAL Instantiation of the ScriptRouteHandler should be cleaned up ILoggerFactory loggerFactory = _config.HostConfig.LoggerFactory; WebJobsRouteBuilder routesBuilder = _router.CreateBuilder(new ScriptRouteHandler(loggerFactory, this, _settingsManager, false), httpConfig.RoutePrefix); // Proxies do not honor the route prefix defined in host.json WebJobsRouteBuilder proxiesRoutesBuilder = _router.CreateBuilder(new ScriptRouteHandler(loggerFactory, this, _settingsManager, true), routePrefix: null); foreach (var function in functions) { var httpTrigger = function.GetTriggerAttributeOrNull <HttpTriggerAttribute>(); if (httpTrigger != null) { var constraints = new RouteValueDictionary(); if (httpTrigger.Methods != null) { constraints.Add("httpMethod", new HttpMethodRouteConstraint(httpTrigger.Methods)); } string route = httpTrigger.Route; if (string.IsNullOrEmpty(route) && !function.Metadata.IsProxy) { route = function.Name; } WebJobsRouteBuilder builder = function.Metadata.IsProxy ? proxiesRoutesBuilder : routesBuilder; builder.MapFunctionRoute(function.Metadata.Name, route, constraints, function.Metadata.Name); } } IRouter proxyRouter = null; IRouter functionRouter = null; if (proxiesRoutesBuilder.Count > 0) { proxyRouter = proxiesRoutesBuilder.Build(); } if (routesBuilder.Count > 0) { functionRouter = routesBuilder.Build(); } _router.AddFunctionRoutes(functionRouter, proxyRouter); }
public void ReorderRoutes() { var unorderedRoutes = _router.GetRoutes(); var routePrecedence = Comparer <Route> .Create(RouteComparison); var orderedRoutes = unorderedRoutes.OrderBy(id => id, routePrecedence); var orderedCollection = new RouteCollection(); foreach (var route in orderedRoutes) { orderedCollection.Add(route); } _router.ClearRoutes(); _router.AddFunctionRoutes(orderedCollection, null); }
public void ReorderRoutes() { var routePrecedence = Comparer <Route> .Create(_options.Comparison); var functionRoutes = _router.GetFunctionRoutes() .ToEnumerable() .OrderBy(id => id, routePrecedence) .ToRouteCollection(); var proxyRoutes = _router.GetProxyRoutes() .ToEnumerable() .OrderBy(id => id, routePrecedence) .ToRouteCollection(); _router.ClearRoutes(); _router.AddFunctionRoutes(functionRoutes, proxyRoutes); }
public void InitializeHttpFunctionRoutes(IScriptJobHost host) { var routesLogBuilder = new StringBuilder(); routesLogBuilder.AppendLine("Initializing function HTTP routes"); _router.ClearRoutes(); // TODO: FACAVAL Instantiation of the ScriptRouteHandler should be cleaned up WebJobsRouteBuilder routesBuilder = _router.CreateBuilder(new ScriptRouteHandler(_loggerFactory, host, _environment, false), _httpOptions.Value.RoutePrefix); // Proxies do not honor the route prefix defined in host.json WebJobsRouteBuilder proxiesRoutesBuilder = _router.CreateBuilder(new ScriptRouteHandler(_loggerFactory, host, _environment, true), routePrefix: null); WebJobsRouteBuilder warmupRouteBuilder = null; if (!_environment.IsLinuxConsumption() && !_environment.IsWindowsConsumption()) { warmupRouteBuilder = _router.CreateBuilder(new ScriptRouteHandler(_loggerFactory, host, _environment, isProxy: false, isWarmup: true), routePrefix: "admin"); } foreach (var function in host.Functions) { var httpTrigger = function.HttpTriggerAttribute; if (httpTrigger != null) { var constraints = new RouteValueDictionary(); if (httpTrigger.Methods != null) { constraints.Add("httpMethod", new HttpMethodRouteConstraint(httpTrigger.Methods)); } string route = httpTrigger.Route; bool isProxy = function.Metadata.IsProxy(); if (string.IsNullOrEmpty(route) && !isProxy) { route = function.Name; } WebJobsRouteBuilder builder = isProxy ? proxiesRoutesBuilder : routesBuilder; builder.MapFunctionRoute(function.Metadata.Name, route, constraints, function.Metadata.Name); LogRouteMap(routesLogBuilder, function.Metadata.Name, route, httpTrigger.Methods, isProxy, _httpOptions.Value.RoutePrefix); } else if (warmupRouteBuilder != null && function.IsWarmupFunction()) { warmupRouteBuilder.MapFunctionRoute(function.Metadata.Name, "warmup", function.Metadata.Name); } } IRouter proxyRouter = null; IRouter functionRouter = null; if (routesBuilder.Count == 0 && proxiesRoutesBuilder.Count == 0) { routesLogBuilder.AppendLine("No HTTP routes mapped"); } else { if (proxiesRoutesBuilder.Count > 0) { proxyRouter = proxiesRoutesBuilder.Build(); } if (routesBuilder.Count > 0) { functionRouter = routesBuilder.Build(); } } _router.AddFunctionRoutes(functionRouter, proxyRouter); if (warmupRouteBuilder != null) { // Adding the default admin/warmup route when no warmup function is present if (warmupRouteBuilder.Count == 0) { warmupRouteBuilder.MapFunctionRoute(string.Empty, "warmup", string.Empty); } IRouter warmupRouter = warmupRouteBuilder.Build(); _router.AddFunctionRoutes(warmupRouter, null); } ILogger logger = _loggerFactory.CreateLogger <WebScriptHostHttpRoutesManager>(); logger.LogInformation(routesLogBuilder.ToString()); }
public void InitializeHttpFunctionRoutes(IScriptJobHost host) { var routesLogBuilder = new StringBuilder(); routesLogBuilder.AppendLine("Initializing function HTTP routes"); _router.ClearRoutes(); // TODO: FACAVAL Instantiation of the ScriptRouteHandler should be cleaned up WebJobsRouteBuilder routesBuilder = _router.CreateBuilder(new ScriptRouteHandler(_loggerFactory, host, _environment, false), _httpOptions.Value.RoutePrefix); // Proxies do not honor the route prefix defined in host.json WebJobsRouteBuilder proxiesRoutesBuilder = _router.CreateBuilder(new ScriptRouteHandler(_loggerFactory, host, _environment, true), routePrefix: null); foreach (var function in host.Functions) { var httpTrigger = function.GetTriggerAttributeOrNull <HttpTriggerAttribute>(); if (httpTrigger != null) { var constraints = new RouteValueDictionary(); if (httpTrigger.Methods != null) { constraints.Add("httpMethod", new HttpMethodRouteConstraint(httpTrigger.Methods)); } string route = httpTrigger.Route; if (string.IsNullOrEmpty(route) && !function.Metadata.IsProxy) { route = function.Name; } WebJobsRouteBuilder builder = function.Metadata.IsProxy ? proxiesRoutesBuilder : routesBuilder; builder.MapFunctionRoute(function.Metadata.Name, route, constraints, function.Metadata.Name); LogRouteMap(routesLogBuilder, function.Metadata.Name, route, httpTrigger.Methods, function.Metadata.IsProxy, _httpOptions.Value.RoutePrefix); } } IRouter proxyRouter = null; IRouter functionRouter = null; if (routesBuilder.Count == 0 && proxiesRoutesBuilder.Count == 0) { routesLogBuilder.AppendLine("No HTTP routes mapped"); } else { if (proxiesRoutesBuilder.Count > 0) { proxyRouter = proxiesRoutesBuilder.Build(); } if (routesBuilder.Count > 0) { functionRouter = routesBuilder.Build(); } } _router.AddFunctionRoutes(functionRouter, proxyRouter); ILogger logger = _loggerFactory.CreateLogger <WebScriptHostHttpRoutesManager>(); logger.LogInformation(routesLogBuilder.ToString()); }