Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Blazor and Frontdoor #59

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/ssw-rulesgpt-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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/<base href="\/" \/>/<base href="\/rulesgpt\/" \/>/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/<base href="\/" \/>/<base href="\/rulesgpt\/" \/>/g' ${{env.DOTNET_ROOT}}/myapp/webui/wwwroot/index.html

- name: Upload API artifact for deployment job
uses: actions/[email protected]
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/ssw-rulesgpt-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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/<base href="\/" \/>/<base href="\/rulesgpt\/" \/>/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/<base href="\/" \/>/<base href="\/rulesgpt\/" \/>/g' ${{env.DOTNET_ROOT}}/myapp/webui/wwwroot/index.html

- name: Upload API artifact for deployment job
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*.user
*.userosscache
*.sln.docstates
**/appsettings.json
**/appsettings.Development.json

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
10 changes: 9 additions & 1 deletion src/WebAPI/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down
10 changes: 10 additions & 0 deletions src/WebAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Information"
}
},
"AllowedHosts": "*"
}
4 changes: 1 addition & 3 deletions src/WebUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 9 additions & 13 deletions src/WebUI/SignalRClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SignalRClient> _logger;
private readonly DataState _dataState;

public SignalRClient(
DataState dataState,
IWebAssemblyHostEnvironment hostEnvironment,
NotifierService notifierService,
ILogger<SignalRClient> logger)
IConfiguration config,
ILogger<SignalRClient> 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);
}
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/WebUI/WebUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
<PackageReference Include="MudBlazor.Markdown" Version="0.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions src/WebUI/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ApiBaseUrl": "https://localhost:7104"
}
2 changes: 1 addition & 1 deletion src/WebUI/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<body>
<div id="app">
<!--Loading...-->
<script src="/js/lottie-player.js"></script>
<!--<script src="js/lottie-player.js"></script>-->

<div class="gpt-loading-info">
<img src="images/SSWlogo.svg" />
Expand Down