public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); StackdriverOptions.ConfigureServices(services, CurrentEnvironment); NetworkOptions.ConfigureServices(services); // TODO: Add actual health checks, maybe. services.AddHealthChecks(); #if BLAZOR services.AddResponseCompression(options => { options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { MediaTypeNames.Application.Octet, WasmMediaTypeNames.Application.Wasm, }); }); #endif var storageOptions = Configuration.GetSection("Storage").Get <StorageOptions>(); storageOptions.ConfigureServices(services); services.AddSingleton <MarkdownLoader>(); services.AddMemoryCache(); }
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); CurrentEnvironment = env; StackdriverOptions = Configuration.GetSection("Stackdriver").Get <StackdriverOptions>(); }
public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); StackdriverOptions.ConfigureServices(services, CurrentEnvironment); NetworkOptions.ConfigureServices(services); // TODO: Add actual health checks, maybe. services.AddHealthChecks(); #if BLAZOR services.AddResponseCompression(options => { options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { MediaTypeNames.Application.Octet, WasmMediaTypeNames.Application.Wasm, }); }); #endif if (UseGoogleCloudStorage) { // Eagerly fetch the GoogleCredential so that we're not using Task.Result in // request processing. services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration)); services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>(); services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>(); services.AddSingleton <IBenchmarkRepository, GoogleStorageBenchmarkRepository>(); } else { services.AddSingleton <IReleaseRepository, FakeReleaseRepository>(); services.AddSingleton <ITzdbRepository, FakeTzdbRepository>(); services.AddSingleton <IBenchmarkRepository, LocalBenchmarkRepository>(); } services.AddSingleton <MarkdownLoader>(); services.AddMemoryCache(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { // Note: health checks come before HTTPS redirection so we get a 200 even on HTTP. app.UseHealthChecks("/healthz"); StackdriverOptions.Configure(app, env, loggerFactory); NetworkOptions.Configure(app, env); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseDefaultFiles(); // Default content, e.g. CSS. // Even though we don't normally host the nzd files locally, it's useful to be able // to in case of emergency. app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = new FileExtensionContentTypeProvider { Mappings = { [".nzd"] = "application/octet-stream" } }, OnPrepareResponse = context => SetCacheControlHeaderForStaticContent(env, context.Context) }); // API documentation app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "docfx")), ContentTypeProvider = new FileExtensionContentTypeProvider { Mappings = { [".yml"] = "text/x-yaml" } }, OnPrepareResponse = context => SetCacheControlHeaderForStaticContent(env, context.Context) }); // Captures "unstable" or a specific version - used several times below. string anyVersion = @"((?:1\.[0-4]\.x)|(?:unstable)|(?:2\.[0-4]\.x))"; var rewriteOptions = new RewriteOptions() // Docfx wants index.html to exist, which is annoying... just redirect. .AddRedirect($@"^index.html$", "/") // We don't have an index.html or equivalent for the APIs, so let's go to NodaTime.html .AddRedirect($@"^{anyVersion}/api/?$", "$1/api/NodaTime.html") // Compatibility with old links .AddRedirect($@"^{anyVersion}/userguide/([^.]+)\.html$", "$1/userguide/$2") .AddRedirect($@"^developer/([^.]+)\.html$", "developer/$1") // Avoid links from userguide/unstable from going to userguide/core-concepts etc // (There are no doubt better ways of doing this...) .AddRedirect($@"^{anyVersion}/userguide$", "$1/userguide/") .AddRedirect($@"^developer$", "developer/") // Make /api and /userguide links to the latest stable release. .AddRedirect("^(api|userguide)(/.*)?$", "2.4.x/$1$2"); app.UseRewriter(rewriteOptions); // At some stage we may want an MVC view for the home page, but at the moment // we're just serving static files, so we don't need much. app.UseMvc(routes => { // TODO: Find a better way of routing. This is pretty nasty. routes.MapRoute("Developer docs", "developer/{*url}", new { controller = "Documentation", bundle = "developer", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("1.0.x user guide", "1.0.x/userguide/{*url}", new { controller = "Documentation", bundle = "1.0.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("1.1.x user guide", "1.1.x/userguide/{*url}", new { controller = "Documentation", bundle = "1.1.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("1.2.x user guide", "1.2.x/userguide/{*url}", new { controller = "Documentation", bundle = "1.2.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("1.3.x user guide", "1.3.x/userguide/{*url}", new { controller = "Documentation", bundle = "1.3.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("1.4.x user guide", "1.4.x/userguide/{*url}", new { controller = "Documentation", bundle = "1.4.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("2.0.x user guide", "2.0.x/userguide/{*url}", new { controller = "Documentation", bundle = "2.0.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("2.1.x user guide", "2.1.x/userguide/{*url}", new { controller = "Documentation", bundle = "2.1.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("2.2.x user guide", "2.2.x/userguide/{*url}", new { controller = "Documentation", bundle = "2.2.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("2.3.x user guide", "2.3.x/userguide/{*url}", new { controller = "Documentation", bundle = "2.3.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("2.4.x user guide", "2.4.x/userguide/{*url}", new { controller = "Documentation", bundle = "2.4.x", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("Unstable user guide", "unstable/userguide/{*url}", new { controller = "Documentation", bundle = "unstable", action = nameof(DocumentationController.ViewDocumentation) }); routes.MapRoute("default", "{action=Index}/{id?}", new { controller = "Home" }); }); // Force all the Markdown to be loaded on startup. app.ApplicationServices.GetRequiredService <MarkdownLoader>(); // Force the set of releases to be first loaded on startup. app.ApplicationServices.GetRequiredService <IReleaseRepository>().GetReleases(); // Force the set of benchmarks to be first loaded on startup. app.ApplicationServices.GetRequiredService <IBenchmarkRepository>().ListEnvironments(); // Force the set of TZDB data to be first loaded on startup. app.ApplicationServices.GetRequiredService <ITzdbRepository>().GetReleases(); #if BLAZOR app.Map("/blazor", child => child.UseBlazor <NodaTime.Web.Blazor.Program>()); #endif }
public UserEventsService(StackdriverOptions options) { _bigQueryClient = BigQueryClient.Create(options.ProjectId); }