From 2e14d3404f1763ed425e2755f7b5e5f737f19fe7 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:46:34 +0100 Subject: [PATCH 01/22] Create GlobalRoutePrefixMiddleware.cs --- .../Middleware/GlobalRoutePrefixMiddleware.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 PxWeb/Middleware/GlobalRoutePrefixMiddleware.cs diff --git a/PxWeb/Middleware/GlobalRoutePrefixMiddleware.cs b/PxWeb/Middleware/GlobalRoutePrefixMiddleware.cs new file mode 100644 index 00000000..518dd356 --- /dev/null +++ b/PxWeb/Middleware/GlobalRoutePrefixMiddleware.cs @@ -0,0 +1,25 @@ +using System.Threading.Tasks; + +using Microsoft.AspNetCore.Http; + +namespace PxWeb.Middleware +{ + + public class GlobalRoutePrefixMiddleware + { + private readonly RequestDelegate _next; + private readonly string _routePrefix; + + public GlobalRoutePrefixMiddleware(RequestDelegate next, string routePrefix) + { + _next = next; + _routePrefix = routePrefix; + } + + public async Task InvokeAsync(HttpContext context) + { + context.Request.PathBase = new PathString(_routePrefix); + await _next(context); + } + } +} From 6a0de9a79e1a435a361f4289559bfa2e23b72ef6 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:46:44 +0100 Subject: [PATCH 02/22] Update Program.cs --- PxWeb/Program.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/PxWeb/Program.cs b/PxWeb/Program.cs index 4b4b3ddf..5acde002 100644 --- a/PxWeb/Program.cs +++ b/PxWeb/Program.cs @@ -6,6 +6,7 @@ using log4net; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -135,12 +136,15 @@ public static void Main(string[] args) var app = builder.Build(); - // Configure the HTTP request pipeline. - if (app.Environment.IsDevelopment()) + app.UseMiddleware("/pxapi2-beta"); + + + app.UseSwagger(); + app.UseSwaggerUI(options => { - app.UseSwagger(); - app.UseSwaggerUI(); - } + options.SwaggerEndpoint("/swagger/v1/swagger.json", "PxWebApi 2.0"); + options.RoutePrefix = "/pxapi2-beta"; + }); app.UseHttpsRedirection(); @@ -160,6 +164,7 @@ public static void Main(string[] args) appBuilder.UseAdminProtectionKey(); }); } + app.UsePathBase(new PathString("/pxapi2-beta")); app.MapControllers(); if (!app.Environment.IsDevelopment()) From 013d44f54730cba033cc39e7135be522f57e86c6 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 10 May 2024 12:50:51 +0200 Subject: [PATCH 03/22] Update appsettings.json --- PxWeb/appsettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PxWeb/appsettings.json b/PxWeb/appsettings.json index 5d29a57f..32273ad9 100644 --- a/PxWeb/appsettings.json +++ b/PxWeb/appsettings.json @@ -39,7 +39,7 @@ "CacheTime": 86400, "SearchEngine": "Lucene", "PageSize": 20, - "BaseURL": "https://www.pxapi.com/api/v2/", + "BaseURL": "/api/v2/", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", @@ -62,7 +62,7 @@ "relational_table", "px" ], - "DefaultOutputFormat": "px" + "DefaultOutputFormat": "json-stat2" }, "LuceneConfiguration": { "IndexDirectory": "Database" From 7e860cb4e58ed9ed66c57889facfe2c3425163b2 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 10 May 2024 12:51:04 +0200 Subject: [PATCH 04/22] Update appsettings.Development.json --- PxWeb/appsettings.Development.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PxWeb/appsettings.Development.json b/PxWeb/appsettings.Development.json index 0c208ae9..df47fa58 100644 --- a/PxWeb/appsettings.Development.json +++ b/PxWeb/appsettings.Development.json @@ -2,7 +2,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Debug", + "PxWeb": "Debug" } } } From 869bdc6326965b1868e6c9d4f5ccb616875ae0a8 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 10 May 2024 12:54:59 +0200 Subject: [PATCH 05/22] Add PxWeb.Api2.Server --- .gitignore | 1 + PxWeb.sln | 6 ++++++ PxWeb/PxWeb.csproj | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index be66735b..3d061109 100644 --- a/.gitignore +++ b/.gitignore @@ -455,3 +455,4 @@ $RECYCLE.BIN/ # PxWebApi PxWeb/wwwroot/ControllerStates/ +PxWeb.Api2.Server/ diff --git a/PxWeb.sln b/PxWeb.sln index 3efb359d..79187ad7 100644 --- a/PxWeb.sln +++ b/PxWeb.sln @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Px.Search.Lucene", "Px.Sear EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PxWebApi.BigTests", "PxWebApi.BigTests\PxWebApi.BigTests.csproj", "{E52A7944-28C6-4004-9282-1AE8BC539F8F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxWeb.Api2.Server", "PxWeb.Api2.Server\PxWeb.Api2.Server.csproj", "{24C58402-46B8-4042-90C2-74B38B847862}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {E52A7944-28C6-4004-9282-1AE8BC539F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU {E52A7944-28C6-4004-9282-1AE8BC539F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {E52A7944-28C6-4004-9282-1AE8BC539F8F}.Release|Any CPU.Build.0 = Release|Any CPU + {24C58402-46B8-4042-90C2-74B38B847862}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24C58402-46B8-4042-90C2-74B38B847862}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24C58402-46B8-4042-90C2-74B38B847862}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24C58402-46B8-4042-90C2-74B38B847862}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PxWeb/PxWeb.csproj b/PxWeb/PxWeb.csproj index 26c3e19b..790b9f16 100644 --- a/PxWeb/PxWeb.csproj +++ b/PxWeb/PxWeb.csproj @@ -39,7 +39,6 @@ - @@ -63,6 +62,7 @@ + From a5be2f51a019ac973296b7a7d572a1ca27daa570 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 10 May 2024 12:59:46 +0200 Subject: [PATCH 06/22] Update appsettings.json --- PxWeb/appsettings.json | 208 ++++++++++++++++++++--------------------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/PxWeb/appsettings.json b/PxWeb/appsettings.json index 5d29a57f..55232e69 100644 --- a/PxWeb/appsettings.json +++ b/PxWeb/appsettings.json @@ -1,104 +1,104 @@ -{ - "DataSource": { - "DataSourceType": "PX", - "PX": { - "StrictAggregations": "true" - }, - "CNMM": { - "DatabaseID": "ssd" - } - }, - "PxApiConfiguration": { - "Languages": [ - { - "Id": "en", - "Label": "English" - }, - { - "Id": "sv", - "Label": "Svenska" - } - ], - "DefaultLanguage": "en", - "MaxDataCells": 10000, - "License": "https://creativecommons.org/share-your-work/public-domain/cc0/", - "SourceReferences": [ - { - "Language": "en", - "Text": "Source: Statistics Sweden" - }, - { - "Language": "sv", - "Text": "Källa: SCB" - } - ], - "Cors": { - "Enabled": true, - "Origins": "*" - }, - "CacheTime": 86400, - "SearchEngine": "Lucene", - "PageSize": 20, - "BaseURL": "https://www.pxapi.com/api/v2/", - "OutputFormats": [ - "xlsx", - "xlsx_doublecolumn", - "csv", - "csv_tab", - "csv_tabhead", - "csv_comma", - "csv_commahead", - "csv_space", - "csv_spacehead", - "csv_semicolon", - "csv_semicolonhead", - "csv2", - "csv3", - "json", - "json-stat", - "json-stat2", - "parquet", - "html5_table", - "relational_table", - "px" - ], - "DefaultOutputFormat": "px" - }, - "LuceneConfiguration": { - "IndexDirectory": "Database" - }, - "AdminProtection": { - "IpWhitelist": ["127.0.0.1", "::1"], - "AdminKey": "test" - }, - "CacheMiddleware": { - "CacheTime": 10, - "BufferThreshold": 40960 - }, - "IpRateLimiting": { - "EnableEndpointRateLimiting": false, - "StackBlockedRequests": false, - "RealIpHeader": "X-Forwarded-For", - "ClientIdHeader": "", - "HttpStatusCode": 429, - "IpWhitelist": ["::1/10", "127.0.0.1"], - "EndpointWhitelist": ["get:/v2/config"], - "ClientWhitelist": [], - "GeneralRules": [ - { - "Endpoint": "*", - "Period": "10s", - "Limit": 30 - } - ] - }, - - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*", - "config1": "" -} +{ + "DataSource": { + "DataSourceType": "PX", + "PX": { + "StrictAggregations": "true" + }, + "CNMM": { + "DatabaseID": "ssd" + } + }, + "PxApiConfiguration": { + "Languages": [ + { + "Id": "en", + "Label": "English" + }, + { + "Id": "sv", + "Label": "Svenska" + } + ], + "DefaultLanguage": "en", + "MaxDataCells": 10000, + "License": "https://creativecommons.org/share-your-work/public-domain/cc0/", + "SourceReferences": [ + { + "Language": "en", + "Text": "Source: Statistics Sweden" + }, + { + "Language": "sv", + "Text": "Källa: SCB" + } + ], + "Cors": { + "Enabled": true, + "Origins": "*" + }, + "CacheTime": 86400, + "SearchEngine": "Lucene", + "PageSize": 20, + "BaseURL": "/api/v2/", + "OutputFormats": [ + "xlsx", + "xlsx_doublecolumn", + "csv", + "csv_tab", + "csv_tabhead", + "csv_comma", + "csv_commahead", + "csv_space", + "csv_spacehead", + "csv_semicolon", + "csv_semicolonhead", + "csv2", + "csv3", + "json", + "json-stat", + "json-stat2", + "parquet", + "html5_table", + "relational_table", + "px" + ], + "DefaultOutputFormat": "jsons-stat2" + }, + "LuceneConfiguration": { + "IndexDirectory": "Database" + }, + "AdminProtection": { + "IpWhitelist": ["127.0.0.1", "::1"], + "AdminKey": "test" + }, + "CacheMiddleware": { + "CacheTime": 10, + "BufferThreshold": 40960 + }, + "IpRateLimiting": { + "EnableEndpointRateLimiting": false, + "StackBlockedRequests": false, + "RealIpHeader": "X-Forwarded-For", + "ClientIdHeader": "", + "HttpStatusCode": 429, + "IpWhitelist": ["::1/10", "127.0.0.1"], + "EndpointWhitelist": ["get:/v2/config"], + "ClientWhitelist": [], + "GeneralRules": [ + { + "Endpoint": "*", + "Period": "10s", + "Limit": 30 + } + ] + }, + + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "config1": "" +} From 77108f10e886dfdac5dc6bb9712eabe7a82a114c Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 10 May 2024 13:20:35 +0200 Subject: [PATCH 07/22] Update appsettings.json --- PxWeb/appsettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PxWeb/appsettings.json b/PxWeb/appsettings.json index 55232e69..c635acc2 100644 --- a/PxWeb/appsettings.json +++ b/PxWeb/appsettings.json @@ -39,7 +39,7 @@ "CacheTime": 86400, "SearchEngine": "Lucene", "PageSize": 20, - "BaseURL": "/api/v2/", + "BaseURL": "/", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", @@ -62,7 +62,7 @@ "relational_table", "px" ], - "DefaultOutputFormat": "jsons-stat2" + "DefaultOutputFormat": "json-stat2" }, "LuceneConfiguration": { "IndexDirectory": "Database" From 08e172c9b396f23aad5667c614e7a16817e2d35a Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 10 May 2024 13:20:48 +0200 Subject: [PATCH 08/22] Update Program.cs --- PxWeb/Program.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/PxWeb/Program.cs b/PxWeb/Program.cs index 32ac1980..66c409b1 100644 --- a/PxWeb/Program.cs +++ b/PxWeb/Program.cs @@ -137,18 +137,20 @@ public static void Main(string[] args) var app = builder.Build(); - app.UseMiddleware("/pxapi2-beta"); + app.UseMiddleware("/api/v2"); app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "PxWebApi 2.0"); - options.RoutePrefix = "/pxapi2-beta"; + options.SwaggerEndpoint("/swagger/v1/swagger.json", "PxWebApi 2.0-beta"); + //options.RoutePrefix = "/api/v2"; }); app.UseHttpsRedirection(); + app.UsePathBase(new PathString("/api/v2")); + if (corsEnbled) { app.UseCors(); @@ -165,7 +167,6 @@ public static void Main(string[] args) appBuilder.UseAdminProtectionKey(); }); } - app.UsePathBase(new PathString("/pxapi2-beta")); app.MapControllers(); if (!app.Environment.IsDevelopment()) From fcc0bee29225ac7d6b587cb30bd979c97eacd029 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Fri, 10 May 2024 14:21:24 +0200 Subject: [PATCH 09/22] .NET 8.0 --- Px.Abstractions/Px.Abstractions.csproj | 2 +- Px.Search.Lucene/Px.Search.Lucene.csproj | 2 +- Px.Search/Px.Search.csproj | 2 +- PxWeb.UnitTests/PxWeb.UnitTests.csproj | 2 +- PxWeb/PxWeb.csproj | 2 +- PxWebApi.BigTests/PxWebApi.BigTests.csproj | 2 +- global.json | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Px.Abstractions/Px.Abstractions.csproj b/Px.Abstractions/Px.Abstractions.csproj index 59af71e8..336ccf88 100644 --- a/Px.Abstractions/Px.Abstractions.csproj +++ b/Px.Abstractions/Px.Abstractions.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/Px.Search.Lucene/Px.Search.Lucene.csproj b/Px.Search.Lucene/Px.Search.Lucene.csproj index 8d15423c..570b45ea 100644 --- a/Px.Search.Lucene/Px.Search.Lucene.csproj +++ b/Px.Search.Lucene/Px.Search.Lucene.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 enable enable diff --git a/Px.Search/Px.Search.csproj b/Px.Search/Px.Search.csproj index 4fa2240d..26e62f3f 100644 --- a/Px.Search/Px.Search.csproj +++ b/Px.Search/Px.Search.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/PxWeb.UnitTests/PxWeb.UnitTests.csproj b/PxWeb.UnitTests/PxWeb.UnitTests.csproj index bc0bec77..225aca52 100644 --- a/PxWeb.UnitTests/PxWeb.UnitTests.csproj +++ b/PxWeb.UnitTests/PxWeb.UnitTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable false diff --git a/PxWeb/PxWeb.csproj b/PxWeb/PxWeb.csproj index 0318637c..78952d82 100644 --- a/PxWeb/PxWeb.csproj +++ b/PxWeb/PxWeb.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable disabled diff --git a/PxWebApi.BigTests/PxWebApi.BigTests.csproj b/PxWebApi.BigTests/PxWebApi.BigTests.csproj index d5504b96..2310806b 100644 --- a/PxWebApi.BigTests/PxWebApi.BigTests.csproj +++ b/PxWebApi.BigTests/PxWebApi.BigTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 enable true false diff --git a/global.json b/global.json index 2ca974fe..090e95c7 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.100", + "version": "8.0.100", "rollForward": "latestFeature" } } From 69a21aa212fc0ac55f7ced4657010a1de121c4cd Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 09:51:00 +0200 Subject: [PATCH 10/22] Update Program.cs --- PxWeb/Program.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/PxWeb/Program.cs b/PxWeb/Program.cs index 66c409b1..7db75cf2 100644 --- a/PxWeb/Program.cs +++ b/PxWeb/Program.cs @@ -136,20 +136,19 @@ public static void Main(string[] args) bool corsEnbled = builder.Services.ConfigurePxCORS(builder, _logger); var app = builder.Build(); + var routePrefix = builder.Configuration.GetSection("PxApiConfiguration:RoutePrefix").Value; - app.UseMiddleware("/api/v2"); - + app.UseMiddleware(routePrefix); + app.UsePathBase(new PathString(routePrefix)); app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "PxWebApi 2.0-beta"); - //options.RoutePrefix = "/api/v2"; }); app.UseHttpsRedirection(); - app.UsePathBase(new PathString("/api/v2")); if (corsEnbled) { From bd6375a59444049507f47bc4751349f1732596ce Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 09:53:01 +0200 Subject: [PATCH 11/22] Update Program.cs --- PxWeb/Program.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PxWeb/Program.cs b/PxWeb/Program.cs index 7db75cf2..6f8aece4 100644 --- a/PxWeb/Program.cs +++ b/PxWeb/Program.cs @@ -141,11 +141,15 @@ public static void Main(string[] args) app.UseMiddleware(routePrefix); app.UsePathBase(new PathString(routePrefix)); - app.UseSwagger(); - app.UseSwaggerUI(options => + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "PxWebApi 2.0-beta"); - }); + app.UseSwagger(); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/swagger/v1/swagger.json", "PxWebApi 2.0-beta"); + }); + } app.UseHttpsRedirection(); From e6c0a76095793a718e39a7ab5cb11a5a5b6fce12 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 09:55:26 +0200 Subject: [PATCH 12/22] Update appsettings.json --- PxWeb/appsettings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/PxWeb/appsettings.json b/PxWeb/appsettings.json index c635acc2..d4354101 100644 --- a/PxWeb/appsettings.json +++ b/PxWeb/appsettings.json @@ -40,6 +40,7 @@ "SearchEngine": "Lucene", "PageSize": 20, "BaseURL": "/", + "RoutePrefix": "/api/v2", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", From 4d5db362f21af6a8ff38458af5495a4b0fb7dcf9 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 09:55:35 +0200 Subject: [PATCH 13/22] Update Program.cs --- PxWeb/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/PxWeb/Program.cs b/PxWeb/Program.cs index 6f8aece4..959fb801 100644 --- a/PxWeb/Program.cs +++ b/PxWeb/Program.cs @@ -153,7 +153,6 @@ public static void Main(string[] args) app.UseHttpsRedirection(); - if (corsEnbled) { app.UseCors(); From eb5e02164922a7bc1ca998e107e52fbe867518b8 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 09:56:20 +0200 Subject: [PATCH 14/22] Update PxApiConfigurationOptions.cs --- PxWeb/Config/Api2/PxApiConfigurationOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PxWeb/Config/Api2/PxApiConfigurationOptions.cs b/PxWeb/Config/Api2/PxApiConfigurationOptions.cs index cbad873e..225344ed 100644 --- a/PxWeb/Config/Api2/PxApiConfigurationOptions.cs +++ b/PxWeb/Config/Api2/PxApiConfigurationOptions.cs @@ -15,6 +15,7 @@ public class PxApiConfigurationOptions public int CacheTime { get; set; } = 5; public int PageSize { get; set; } public string BaseURL { get; set; } = String.Empty; + public string RoutePrefix { get; set; } = String.Empty; public List OutputFormats { get; set; } = new List(); public string DefaultOutputFormat { get; set; } = String.Empty; From cdc34aa65befed0186eed336a37cf9632c4855b4 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 09:57:24 +0200 Subject: [PATCH 15/22] Remove trailing slash in BaseURL --- PxWeb/Mappers/LinkCreator.cs | 2 ++ PxWeb/appsettings.json | 2 +- PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json | 2 +- PxWebApi.BigTests/ConfigController/test_appsettings.json | 2 +- PxWebApi.BigTests/TableController/test_appsettings.json | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/PxWeb/Mappers/LinkCreator.cs b/PxWeb/Mappers/LinkCreator.cs index 251ce2ec..72674690 100644 --- a/PxWeb/Mappers/LinkCreator.cs +++ b/PxWeb/Mappers/LinkCreator.cs @@ -99,6 +99,7 @@ private string CreateURL(string endpointUrl, string language, bool showLangParam StringBuilder sb = new StringBuilder(); sb.Append(_urlBase); + sb.Append("/"); sb.Append(endpointUrl); if (showLangParam) @@ -114,6 +115,7 @@ private string CreatePageURL(string endpointUrl, string language, bool showLangP StringBuilder sb = new StringBuilder(); sb.Append(_urlBase); + sb.Append("/"); sb.Append(endpointUrl); if (!string.IsNullOrEmpty(query) && showLangParam) diff --git a/PxWeb/appsettings.json b/PxWeb/appsettings.json index d4354101..b115ebae 100644 --- a/PxWeb/appsettings.json +++ b/PxWeb/appsettings.json @@ -39,7 +39,7 @@ "CacheTime": 86400, "SearchEngine": "Lucene", "PageSize": 20, - "BaseURL": "/", + "BaseURL": "https://www.pxapi.com/api/v2", "RoutePrefix": "/api/v2", "OutputFormats": [ "xlsx", diff --git a/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json b/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json index 5d29a57f..63471fac 100644 --- a/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json +++ b/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json @@ -39,7 +39,7 @@ "CacheTime": 86400, "SearchEngine": "Lucene", "PageSize": 20, - "BaseURL": "https://www.pxapi.com/api/v2/", + "BaseURL": "https://www.pxapi.com/api/v2", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", diff --git a/PxWebApi.BigTests/ConfigController/test_appsettings.json b/PxWebApi.BigTests/ConfigController/test_appsettings.json index 93b0574c..36747f36 100644 --- a/PxWebApi.BigTests/ConfigController/test_appsettings.json +++ b/PxWebApi.BigTests/ConfigController/test_appsettings.json @@ -40,7 +40,7 @@ "CacheTime": 86400, "SearchEngine": "Lucene", "PageSize": 20, - "BaseURL": "https://www.pxapi.com/api/v2/", + "BaseURL": "https://www.pxapi.com/api/v2", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", diff --git a/PxWebApi.BigTests/TableController/test_appsettings.json b/PxWebApi.BigTests/TableController/test_appsettings.json index 93b0574c..36747f36 100644 --- a/PxWebApi.BigTests/TableController/test_appsettings.json +++ b/PxWebApi.BigTests/TableController/test_appsettings.json @@ -40,7 +40,7 @@ "CacheTime": 86400, "SearchEngine": "Lucene", "PageSize": 20, - "BaseURL": "https://www.pxapi.com/api/v2/", + "BaseURL": "https://www.pxapi.com/api/v2", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", From 733d3fb93ef1132072787d96e1877bffba499483 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 09:59:16 +0200 Subject: [PATCH 16/22] Update appsettings.json --- PxWeb/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PxWeb/appsettings.json b/PxWeb/appsettings.json index b115ebae..a7bc6758 100644 --- a/PxWeb/appsettings.json +++ b/PxWeb/appsettings.json @@ -63,7 +63,7 @@ "relational_table", "px" ], - "DefaultOutputFormat": "json-stat2" + "DefaultOutputFormat": "px" }, "LuceneConfiguration": { "IndexDirectory": "Database" From d77a7707039b3813a24dd7ef5b61821a8420e819 Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 10:06:55 +0200 Subject: [PATCH 17/22] Add RoutePrefix --- PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json | 1 + PxWebApi.BigTests/ConfigController/test_appsettings.json | 1 + PxWebApi.BigTests/TableController/test_appsettings.json | 1 + 3 files changed, 3 insertions(+) diff --git a/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json b/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json index 63471fac..5200f64c 100644 --- a/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json +++ b/PxWebApi.BigTests/AdminDatabaseController/test_appsettings.json @@ -40,6 +40,7 @@ "SearchEngine": "Lucene", "PageSize": 20, "BaseURL": "https://www.pxapi.com/api/v2", + "RoutePrefix": "/api/v2", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", diff --git a/PxWebApi.BigTests/ConfigController/test_appsettings.json b/PxWebApi.BigTests/ConfigController/test_appsettings.json index 36747f36..ac527803 100644 --- a/PxWebApi.BigTests/ConfigController/test_appsettings.json +++ b/PxWebApi.BigTests/ConfigController/test_appsettings.json @@ -41,6 +41,7 @@ "SearchEngine": "Lucene", "PageSize": 20, "BaseURL": "https://www.pxapi.com/api/v2", + "RoutePrefix": "/api/v2", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", diff --git a/PxWebApi.BigTests/TableController/test_appsettings.json b/PxWebApi.BigTests/TableController/test_appsettings.json index 36747f36..ac527803 100644 --- a/PxWebApi.BigTests/TableController/test_appsettings.json +++ b/PxWebApi.BigTests/TableController/test_appsettings.json @@ -41,6 +41,7 @@ "SearchEngine": "Lucene", "PageSize": 20, "BaseURL": "https://www.pxapi.com/api/v2", + "RoutePrefix": "/api/v2", "OutputFormats": [ "xlsx", "xlsx_doublecolumn", From 5b5dca99667d80824a2f227500faf73ad4f1dafa Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 11:15:42 +0200 Subject: [PATCH 18/22] Update NavigationApiController.cs --- PxWeb/Controllers/Api2/NavigationApiController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PxWeb/Controllers/Api2/NavigationApiController.cs b/PxWeb/Controllers/Api2/NavigationApiController.cs index 4b6debba..06c74280 100644 --- a/PxWeb/Controllers/Api2/NavigationApiController.cs +++ b/PxWeb/Controllers/Api2/NavigationApiController.cs @@ -45,7 +45,7 @@ public NavigationApiController(IDataSource dataSource, ILanguageHelper languageH /// /// Gets navigation item with the given id. /// HttpGet - /// Route /api/v2/navigation/{id} + /// Route /navigation/{id} /// /// Id /// The language if the default is not what you want. @@ -61,7 +61,7 @@ public override IActionResult GetNavigationById([FromRoute(Name = "id"), Require /// /// Browse the database structure /// HttpGet - /// Route /api/v2/navigation + /// Route /navigation /// /// The language if the default is not what you want. /// Success From 6ea2baeabdf269a96db0f118b4a33e213ee27a7e Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 12:49:27 +0200 Subject: [PATCH 19/22] Remove /api/v2 from Routes --- PxWeb/Controllers/Api2/Admin/CacheController.cs | 2 +- PxWeb/Controllers/Api2/Admin/DatabaseController.cs | 4 ++-- PxWeb/Controllers/Api2/Admin/SearchindexController.cs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PxWeb/Controllers/Api2/Admin/CacheController.cs b/PxWeb/Controllers/Api2/Admin/CacheController.cs index 8916eb52..eb502374 100644 --- a/PxWeb/Controllers/Api2/Admin/CacheController.cs +++ b/PxWeb/Controllers/Api2/Admin/CacheController.cs @@ -15,7 +15,7 @@ public CacheController(IPxCache pxCache) } [HttpDelete] - [Route("/api/v2/admin/cache")] + [Route("/admin/cache")] public IActionResult Clear() { _pxCache.Clear(); diff --git a/PxWeb/Controllers/Api2/Admin/DatabaseController.cs b/PxWeb/Controllers/Api2/Admin/DatabaseController.cs index c129f629..7cb678b1 100644 --- a/PxWeb/Controllers/Api2/Admin/DatabaseController.cs +++ b/PxWeb/Controllers/Api2/Admin/DatabaseController.cs @@ -45,7 +45,7 @@ public DatabaseController(IControllerStateProvider stateProvider, BackgroundWork } [HttpPut] - [Route("/api/v2/admin/database")] + [Route("/admin/database")] [SwaggerOperation("Database")] [SwaggerResponse(statusCode: 202, description: "Accepted")] [SwaggerResponse(statusCode: 401, description: "Unauthorized")] @@ -109,7 +109,7 @@ internal async Task createMenuXml(bool? langDependent, string? sortOrder, Cancel } [HttpGet] - [Route("/api/v2/admin/database")] + [Route("/admin/database")] [SwaggerOperation("Database")] [SwaggerResponse(statusCode: 200, description: "Success")] [SwaggerResponse(statusCode: 401, description: "Unauthorized")] diff --git a/PxWeb/Controllers/Api2/Admin/SearchindexController.cs b/PxWeb/Controllers/Api2/Admin/SearchindexController.cs index f23f3d72..bab95459 100644 --- a/PxWeb/Controllers/Api2/Admin/SearchindexController.cs +++ b/PxWeb/Controllers/Api2/Admin/SearchindexController.cs @@ -43,7 +43,7 @@ public SearchindexController(BackgroundWorkerQueue backgroundWorkerQueue, IContr /// /// [HttpPost] - [Route("/api/v2/admin/searchindex")] + [Route("/admin/searchindex")] [SwaggerOperation("IndexDatabase")] [SwaggerResponse(statusCode: 202, description: "Accepted")] [SwaggerResponse(statusCode: 401, description: "Unauthorized")] @@ -84,7 +84,7 @@ public IActionResult IndexDatabase() /// /// [HttpPatch] - [Route("/api/v2/admin/searchindex")] + [Route("/admin/searchindex")] [SwaggerOperation("IndexDatabase")] [SwaggerResponse(statusCode: 202, description: "Accepted")] [SwaggerResponse(statusCode: 401, description: "Unauthorized")] @@ -135,7 +135,7 @@ public IActionResult IndexDatabase([FromBody, Required] string[] tables) } [HttpGet] - [Route("/api/v2/admin/searchindex")] + [Route("/admin/searchindex")] [SwaggerOperation("IndexDatabase")] [SwaggerResponse(statusCode: 200, description: "Success")] [SwaggerResponse(statusCode: 401, description: "Unauthorized")] From 32bf3e77009323819f7814d3c8665e803d3e64db Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 21 May 2024 12:49:39 +0200 Subject: [PATCH 20/22] Update Program.cs --- PxWeb/Program.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/PxWeb/Program.cs b/PxWeb/Program.cs index 959fb801..015d0ef0 100644 --- a/PxWeb/Program.cs +++ b/PxWeb/Program.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; @@ -129,6 +130,12 @@ public static void Main(string[] args) { // Sort endpoints c.OrderActionsBy((apiDesc) => $"{apiDesc.ActionDescriptor.RouteValues["controller"]}_{apiDesc.RelativePath}"); + c.SwaggerDoc("v2", new OpenApiInfo + { + Title = "PxWebApi", + Version = "v2-beta" + } + ); }); @@ -147,7 +154,7 @@ public static void Main(string[] args) app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "PxWebApi 2.0-beta"); + options.SwaggerEndpoint("/swagger/v2/swagger.json", "PxWebApi 2.0-beta"); }); } From 29bf269b50a07f804c4de71cf1116c06ab9cf1de Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:50:51 +0200 Subject: [PATCH 21/22] Update Program.cs --- PxWeb/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PxWeb/Program.cs b/PxWeb/Program.cs index 015d0ef0..779fd663 100644 --- a/PxWeb/Program.cs +++ b/PxWeb/Program.cs @@ -170,7 +170,7 @@ public static void Main(string[] args) { app.UseAuthorization(); - app.UseWhen(context => context.Request.Path.StartsWithSegments("/api/v2/admin"), appBuilder => + app.UseWhen(context => context.Request.Path.StartsWithSegments(routePrefix + "/admin") || context.Request.Path.StartsWithSegments("/admin"), appBuilder => { appBuilder.UseAdminProtectionIpWhitelist(); appBuilder.UseAdminProtectionKey(); @@ -183,7 +183,7 @@ public static void Main(string[] args) app.UseIpRateLimiting(); } - app.UseWhen(context => !context.Request.Path.StartsWithSegments("/api/v2/admin"), appBuilder => + app.UseWhen(context => !context.Request.Path.StartsWithSegments(routePrefix + "/admin") || context.Request.Path.StartsWithSegments("/admin"), appBuilder => { appBuilder.UseCacheMiddleware(); }); From b88e5d9d9d2a1a35edad67744c281985c24e384b Mon Sep 17 00:00:00 2001 From: Rune Johansen <6797636+runejo@users.noreply.github.com> Date: Tue, 4 Jun 2024 11:05:50 +0200 Subject: [PATCH 22/22] Revert testing changes --- .gitignore | 1 - PxWeb.sln | 6 ------ PxWeb/PxWeb.csproj | 3 +-- PxWeb/appsettings.Development.json | 3 +-- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 3d061109..be66735b 100644 --- a/.gitignore +++ b/.gitignore @@ -455,4 +455,3 @@ $RECYCLE.BIN/ # PxWebApi PxWeb/wwwroot/ControllerStates/ -PxWeb.Api2.Server/ diff --git a/PxWeb.sln b/PxWeb.sln index 79187ad7..3efb359d 100644 --- a/PxWeb.sln +++ b/PxWeb.sln @@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Px.Search.Lucene", "Px.Sear EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PxWebApi.BigTests", "PxWebApi.BigTests\PxWebApi.BigTests.csproj", "{E52A7944-28C6-4004-9282-1AE8BC539F8F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PxWeb.Api2.Server", "PxWeb.Api2.Server\PxWeb.Api2.Server.csproj", "{24C58402-46B8-4042-90C2-74B38B847862}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,10 +45,6 @@ Global {E52A7944-28C6-4004-9282-1AE8BC539F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU {E52A7944-28C6-4004-9282-1AE8BC539F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {E52A7944-28C6-4004-9282-1AE8BC539F8F}.Release|Any CPU.Build.0 = Release|Any CPU - {24C58402-46B8-4042-90C2-74B38B847862}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {24C58402-46B8-4042-90C2-74B38B847862}.Debug|Any CPU.Build.0 = Debug|Any CPU - {24C58402-46B8-4042-90C2-74B38B847862}.Release|Any CPU.ActiveCfg = Release|Any CPU - {24C58402-46B8-4042-90C2-74B38B847862}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PxWeb/PxWeb.csproj b/PxWeb/PxWeb.csproj index e024c91a..d8450dd1 100644 --- a/PxWeb/PxWeb.csproj +++ b/PxWeb/PxWeb.csproj @@ -39,7 +39,7 @@ - + @@ -63,7 +63,6 @@ - diff --git a/PxWeb/appsettings.Development.json b/PxWeb/appsettings.Development.json index df47fa58..0c208ae9 100644 --- a/PxWeb/appsettings.Development.json +++ b/PxWeb/appsettings.Development.json @@ -2,8 +2,7 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Debug", - "PxWeb": "Debug" + "Microsoft.AspNetCore": "Warning" } } }