diff --git a/.github/workflows/ssw-rulesgpt-prod.yml b/.github/workflows/ssw-rulesgpt-prod.yml index 62e34a7..11353f4 100644 --- a/.github/workflows/ssw-rulesgpt-prod.yml +++ b/.github/workflows/ssw-rulesgpt-prod.yml @@ -12,6 +12,7 @@ on: env: # DeploymentEnvironment: 'Production' AzureWebAppName: 'ssw-rulesgpt-api' # The name of the resource in Azure + AzureWebAppUrl: 'https:\/\/ssw-rulesgpt-api.azurewebsites.net' # Escape slashes for regex AzureWebAppSecret: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_1FEDFC8C3C4A497399C6318E5C173C42 }} AzureStaticWebAppsApiToken: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_WHITE_DESERT_00E3FB600 }} GithubRepoToken: ${{ secrets.GITHUB_TOKEN }} @@ -31,16 +32,19 @@ jobs: - name: Build with dotnet run: dotnet build --configuration Release + - name: Change ApiBaseUrl in appsettings.json from localhost to Azure Web App + run: sed -i 's/https:\/\/localhost:7104/${{env.AzureWebAppUrl}}/g' ./src/WebUI/wwwroot/appsettings.json + - name: dotnet publish WebAPI run: dotnet publish ./src/WebAPI -c Release --property PublishDir=${{env.DOTNET_ROOT}}/myapp/api - name: dotnet publish WebUI run: dotnet publish ./src/WebUI -c Release --property PublishDir=${{env.DOTNET_ROOT}}/myapp/webui # TODO: Build and run unit tests - - # Changes the base-tag in index.html from '/' to 'rulesgpt' to match SSW subdirectory - # - name: Change base-tag in index.html from / to rulesgpt - # run: sed -i 's///g' ${{env.DOTNET_ROOT}}/myapp/webui/wwwroot/index.html + + # Changes the basehref in index.html from '/' to '/rulesgpt/' to match SSW subdirectory + - name: Change basehref in index.html from / to /rulesgpt/ + run: sed -i 's///g' ${{env.DOTNET_ROOT}}/myapp/webui/wwwroot/index.html - name: Upload API artifact for deployment job uses: actions/upload-artifact@v3.1.2 diff --git a/.github/workflows/ssw-rulesgpt-stage.yml b/.github/workflows/ssw-rulesgpt-stage.yml index bf40529..0611d03 100644 --- a/.github/workflows/ssw-rulesgpt-stage.yml +++ b/.github/workflows/ssw-rulesgpt-stage.yml @@ -12,6 +12,7 @@ on: env: # DeploymentEnvironment: 'Staging' AzureWebAppName: 'ssw-rulesgpt-api-stage' # The name of the resource in Azure + AzureWebAppUrl: 'https:\/\/ssw-rulesgpt-api-stage.azurewebsites.net' # Escape slashes for regex AzureWebAppSecret: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_706C909B7DCB4379927A9D3AF3D8B5EF }} AzureStaticWebAppsApiToken: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ASHY_MEADOW_0A2BAD900 }} GithubRepoToken: ${{ secrets.GITHUB_TOKEN }} @@ -31,16 +32,19 @@ jobs: - name: Build with dotnet run: dotnet build --configuration Release + - name: Change ApiBaseUrl in appsettings.json from localhost to Azure Web App + run: sed -i 's/https:\/\/localhost:7104/${{env.AzureWebAppUrl}}/g' ./src/WebUI/wwwroot/appsettings.json + - name: dotnet publish WebAPI run: dotnet publish ./src/WebAPI -c Release --property PublishDir=${{env.DOTNET_ROOT}}/myapp/api - name: dotnet publish WebUI run: dotnet publish ./src/WebUI -c Release --property PublishDir=${{env.DOTNET_ROOT}}/myapp/webui -# TODO: Build and run unit tests + # TODO: Build and run unit tests -# Changes the base-tag in index.html from '/' to 'rulesgpt' to match SSW subdirectory -# - name: Change base-tag in index.html from / to rulesgpt -# run: sed -i 's///g' ${{env.DOTNET_ROOT}}/myapp/webui/wwwroot/index.html + # Changes the basehref in index.html from '/' to '/rulesgpt/' to match SSW subdirectory + - name: Change basehref in index.html from / to /rulesgpt/ + run: sed -i 's///g' ${{env.DOTNET_ROOT}}/myapp/webui/wwwroot/index.html - name: Upload API artifact for deployment job uses: actions/upload-artifact@v3.1.2 diff --git a/.gitignore b/.gitignore index 918eed5..38f6bbe 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ *.user *.userosscache *.sln.docstates -**/appsettings.json +**/appsettings.Development.json # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/src/WebAPI/DependencyInjection.cs b/src/WebAPI/DependencyInjection.cs index 850f6b6..a916058 100644 --- a/src/WebAPI/DependencyInjection.cs +++ b/src/WebAPI/DependencyInjection.cs @@ -39,9 +39,17 @@ string rulesGptCorsPolicy // TODO: Set CORS in Bicep var productionCorsUrls = new string[] { + // Static Web Apps "https://white-desert-00e3fb600.3.azurestaticapps.net", + "https://ashy-meadow-0a2bad900.3.azurestaticapps.net", + // Production "https://rulesgpt.ssw.com.au", - "https://ssw.com.au/rulesgpt" + "https://ssw.com.au/rulesgpt", + "https://ssw.com.au", // TODO: Fix Host Origin Header + // Staging + "https://www.tfs365.com/rulesgpt", + "https://www.tfs365.com", // TODO: Fix Host Origin Header + "https://tfs365.com" // TODO: Fix Host Origin Header }; var developmentCorsUrls = new string[] { "https://localhost:5001" }; diff --git a/src/WebAPI/appsettings.json b/src/WebAPI/appsettings.json new file mode 100644 index 0000000..7aa06ad --- /dev/null +++ b/src/WebAPI/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore.Database.Command": "Information" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file diff --git a/src/WebUI/Program.cs b/src/WebUI/Program.cs index 7423e8b..0587f05 100644 --- a/src/WebUI/Program.cs +++ b/src/WebUI/Program.cs @@ -37,9 +37,7 @@ const string ApiClient = nameof(ApiClient); -var apiBaseUrl = builder.HostEnvironment.IsDevelopment() - ? "https://localhost:7104" - : "https://ssw-rulesgpt-api.azurewebsites.net"; +var apiBaseUrl = builder.Configuration["ApiBaseUrl"]; builder.Services .AddHttpClient( diff --git a/src/WebUI/SignalRClient.cs b/src/WebUI/SignalRClient.cs index 935f8f2..51b164f 100644 --- a/src/WebUI/SignalRClient.cs +++ b/src/WebUI/SignalRClient.cs @@ -3,37 +3,33 @@ using Microsoft.AspNetCore.SignalR.Client; using OpenAI.GPT3.ObjectModels.RequestModels; using WebUI.Models; -using WebUI.Services; namespace WebUI; public class SignalRClient { - private readonly DataState _dataState; - private readonly NotifierService _notifierService; private readonly HubConnection _connection; private readonly ILogger _logger; + private readonly DataState _dataState; public SignalRClient( - DataState dataState, IWebAssemblyHostEnvironment hostEnvironment, - NotifierService notifierService, - ILogger logger) + IConfiguration config, + ILogger logger, + DataState dataState + ) { - _dataState = dataState; - _notifierService = notifierService; _logger = logger; - var hubeBaseUrl = hostEnvironment.IsDevelopment() - ? "https://localhost:7104" - : "https://ssw-rulesgpt-api.azurewebsites.net"; - var hubUrl = $"{hubeBaseUrl}/ruleshub"; + _dataState = dataState; + var hubBaseUrl = config["ApiBaseUrl"]; + var hubUrl = $"{hubBaseUrl}/ruleshub"; _connection = new HubConnectionBuilder().WithUrl(hubUrl).WithAutomaticReconnect().Build(); RegisterHandlers(); _connection.Closed += async (exception) => { if (exception != null) { - _logger.LogInformation("Connection closed due to an error: {Exception}", exception); + _logger.LogInformation("Connection closed due to an error: {Exception}", exception); } }; } diff --git a/src/WebUI/WebUI.csproj b/src/WebUI/WebUI.csproj index 7ae92d3..e8554e7 100644 --- a/src/WebUI/WebUI.csproj +++ b/src/WebUI/WebUI.csproj @@ -17,5 +17,11 @@ + + + + PreserveNewest + + \ No newline at end of file diff --git a/src/WebUI/wwwroot/appsettings.json b/src/WebUI/wwwroot/appsettings.json new file mode 100644 index 0000000..1f309fd --- /dev/null +++ b/src/WebUI/wwwroot/appsettings.json @@ -0,0 +1,3 @@ +{ + "ApiBaseUrl": "https://localhost:7104" +} \ No newline at end of file diff --git a/src/WebUI/wwwroot/index.html b/src/WebUI/wwwroot/index.html index 7e5778f..6b6b50f 100644 --- a/src/WebUI/wwwroot/index.html +++ b/src/WebUI/wwwroot/index.html @@ -53,7 +53,7 @@
- +