From 20cca7bb388da7b083157364e8fb081640c1e46d Mon Sep 17 00:00:00 2001 From: Chandradev Date: Sat, 5 Jul 2025 22:42:38 +0530 Subject: [PATCH 01/11] ci: add Azure Static Web Apps workflow file on-behalf-of: @Azure opensource@microsoft.com --- ...static-web-apps-orange-water-0badfae10.yml | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/azure-static-web-apps-orange-water-0badfae10.yml diff --git a/.github/workflows/azure-static-web-apps-orange-water-0badfae10.yml b/.github/workflows/azure-static-web-apps-orange-water-0badfae10.yml new file mode 100644 index 0000000..57aadcc --- /dev/null +++ b/.github/workflows/azure-static-web-apps-orange-water-0badfae10.yml @@ -0,0 +1,46 @@ +name: Azure Static Web Apps CI/CD + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened, closed] + branches: + - main + +jobs: + build_and_deploy_job: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + runs-on: ubuntu-latest + name: Build and Deploy Job + steps: + - uses: actions/checkout@v3 + with: + submodules: true + lfs: false + - name: Build And Deploy + id: builddeploy + uses: Azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ORANGE_WATER_0BADFAE10 }} + repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) + action: "upload" + ###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### + # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig + app_location: "./Client" # App source code path + api_location: "Api" # Api source code path - optional + output_location: "wwwroot" # Built app content directory - optional + ###### End of Repository/Build Configurations ###### + + close_pull_request_job: + if: github.event_name == 'pull_request' && github.event.action == 'closed' + runs-on: ubuntu-latest + name: Close Pull Request Job + steps: + - name: Close Pull Request + id: closepullrequest + uses: Azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ORANGE_WATER_0BADFAE10 }} + action: "close" From e1d7c6d5608067ddde793f64311ffe798e8be094 Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Sun, 6 Jul 2025 19:52:27 +0530 Subject: [PATCH 02/11] PWA features Added. --- .../WeatherForecastFunction.cs | 2 +- Client/wwwroot/index.html | 4 ++ Client/wwwroot/manifest.webmanifest | 22 ++++++++ Client/wwwroot/service-worker.js | 4 ++ Client/wwwroot/service-worker.published.js | 55 +++++++++++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) rename Api/{ => Functions}/WeatherForecastFunction.cs (98%) create mode 100644 Client/wwwroot/manifest.webmanifest create mode 100644 Client/wwwroot/service-worker.js create mode 100644 Client/wwwroot/service-worker.published.js diff --git a/Api/WeatherForecastFunction.cs b/Api/Functions/WeatherForecastFunction.cs similarity index 98% rename from Api/WeatherForecastFunction.cs rename to Api/Functions/WeatherForecastFunction.cs index 706badb..2875c93 100644 --- a/Api/WeatherForecastFunction.cs +++ b/Api/Functions/WeatherForecastFunction.cs @@ -4,7 +4,7 @@ using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; -namespace Api +namespace Api.Functions { public class HttpTrigger { diff --git a/Client/wwwroot/index.html b/Client/wwwroot/index.html index efc9613..f5ad03f 100644 --- a/Client/wwwroot/index.html +++ b/Client/wwwroot/index.html @@ -10,6 +10,9 @@ + + + @@ -27,6 +30,7 @@ 🗙 + diff --git a/Client/wwwroot/manifest.webmanifest b/Client/wwwroot/manifest.webmanifest new file mode 100644 index 0000000..00ba795 --- /dev/null +++ b/Client/wwwroot/manifest.webmanifest @@ -0,0 +1,22 @@ +{ + "name": "BlazorApp15", + "short_name": "BlazorApp15", + "id": "./", + "start_url": "./", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#03173d", + "prefer_related_applications": false, + "icons": [ + { + "src": "icon-512.png", + "type": "image/png", + "sizes": "512x512" + }, + { + "src": "icon-192.png", + "type": "image/png", + "sizes": "192x192" + } + ] +} diff --git a/Client/wwwroot/service-worker.js b/Client/wwwroot/service-worker.js new file mode 100644 index 0000000..fe614da --- /dev/null +++ b/Client/wwwroot/service-worker.js @@ -0,0 +1,4 @@ +// In development, always fetch from the network and do not enable offline support. +// This is because caching would make development more difficult (changes would not +// be reflected on the first load after each change). +self.addEventListener('fetch', () => { }); diff --git a/Client/wwwroot/service-worker.published.js b/Client/wwwroot/service-worker.published.js new file mode 100644 index 0000000..1f7f543 --- /dev/null +++ b/Client/wwwroot/service-worker.published.js @@ -0,0 +1,55 @@ +// Caution! Be sure you understand the caveats before publishing an application with +// offline support. See https://aka.ms/blazor-offline-considerations + +self.importScripts('./service-worker-assets.js'); +self.addEventListener('install', event => event.waitUntil(onInstall(event))); +self.addEventListener('activate', event => event.waitUntil(onActivate(event))); +self.addEventListener('fetch', event => event.respondWith(onFetch(event))); + +const cacheNamePrefix = 'offline-cache-'; +const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`; +const offlineAssetsInclude = [ /\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/ ]; +const offlineAssetsExclude = [ /^service-worker\.js$/ ]; + +// Replace with your base path if you are hosting on a subfolder. Ensure there is a trailing '/'. +const base = "/"; +const baseUrl = new URL(base, self.origin); +const manifestUrlList = self.assetsManifest.assets.map(asset => new URL(asset.url, baseUrl).href); + +async function onInstall(event) { + console.info('Service worker: Install'); + + // Fetch and cache all matching items from the assets manifest + const assetsRequests = self.assetsManifest.assets + .filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url))) + .filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url))) + .map(asset => new Request(asset.url, { integrity: asset.hash, cache: 'no-cache' })); + await caches.open(cacheName).then(cache => cache.addAll(assetsRequests)); +} + +async function onActivate(event) { + console.info('Service worker: Activate'); + + // Delete unused caches + const cacheKeys = await caches.keys(); + await Promise.all(cacheKeys + .filter(key => key.startsWith(cacheNamePrefix) && key !== cacheName) + .map(key => caches.delete(key))); +} + +async function onFetch(event) { + let cachedResponse = null; + if (event.request.method === 'GET') { + // For all navigation requests, try to serve index.html from cache, + // unless that request is for an offline resource. + // If you need some URLs to be server-rendered, edit the following check to exclude those URLs + const shouldServeIndexHtml = event.request.mode === 'navigate' + && !manifestUrlList.some(url => url === event.request.url); + + const request = shouldServeIndexHtml ? 'index.html' : event.request; + const cache = await caches.open(cacheName); + cachedResponse = await cache.match(request); + } + + return cachedResponse || fetch(event.request); +} From eb0e2c4ef52652e876a5f16a18b60d38791b58d3 Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Sun, 6 Jul 2025 20:15:20 +0530 Subject: [PATCH 03/11] Home Page. --- Client/Pages/Home.razor | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Client/Pages/Home.razor b/Client/Pages/Home.razor index dfcdf75..b60adb9 100644 --- a/Client/Pages/Home.razor +++ b/Client/Pages/Home.razor @@ -2,6 +2,4 @@ Home -

Hello, world!

- -Welcome to your new app. \ No newline at end of file +

Welcome to Bill Me App.

From 7b485e938b3d026ac6613b7cfd84874ff1740a3e Mon Sep 17 00:00:00 2001 From: Chandradev Date: Sun, 6 Jul 2025 21:59:38 +0530 Subject: [PATCH 04/11] Update README.md --- README.md | 66 +------------------------------------------------------ 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/README.md b/README.md index f739d39..fa811de 100644 --- a/README.md +++ b/README.md @@ -1,65 +1 @@ -# Blazor Starter Application - -This template contains an example .NET 8 [Blazor WebAssembly](https://docs.microsoft.com/aspnet/core/blazor/?view=aspnetcore-6.0#blazor-webassembly) client application, a .NET 8 C# [Azure Functions](https://docs.microsoft.com/azure/azure-functions/functions-overview), and a C# class library with shared code. - -## Getting Started - -1. Create a repository from the [GitHub template](https://docs.github.com/en/enterprise/2.22/user/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) and then clone it locally to your machine. - -1. In the **Api** folder, copy `local.settings.example.json` to `local.settings.json` - -1. Continue using either Visual Studio or Visual Studio Code. - -### Visual Studio 2022 - -Once you clone the project, open the solution in the latest release of [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) with the Azure workload installed, and follow these steps: - -1. Right-click on the solution and select **Configure Startup Projects...**. - -1. Select **Multiple startup projects** and set the following actions for each project: - - *Api* - **Start** - - *Client* - **Start** - - *Shared* - None - -1. Press **F5** to launch both the client application and the Functions API app. - -### Visual Studio Code with Azure Static Web Apps CLI for a better development experience (Optional) - -1. Install (or update) the [Azure Static Web Apps CLI](https://www.npmjs.com/package/@azure/static-web-apps-cli) and [Azure Functions Core Tools CLI](https://www.npmjs.com/package/azure-functions-core-tools). - -1. Open the folder in Visual Studio Code. - -1. Delete file `Client/wwwroot/appsettings.Development.json` - -1. In the VS Code terminal, run the following command to start the Static Web Apps CLI, along with the Blazor WebAssembly client application and the Functions API app: - - In the Client folder, run: - ```bash - dotnet run - ``` - - In the API folder, run: - ```bash - func start - ``` - - In another terminal, run: - ```bash - swa start http://localhost:5000 --api-location http://localhost:7071 - ``` - - The Static Web Apps CLI (`swa`) starts a proxy on port 4280 that will forward static site requests to the Blazor server on port 5000 and requests to the `/api` endpoint to the Functions server. - -1. Open a browser and navigate to the Static Web Apps CLI's address at `http://localhost:4280`. You'll be able to access both the client application and the Functions API app in this single address. When you navigate to the "Fetch Data" page, you'll see the data returned by the Functions API app. - -1. Enter Ctrl-C to stop the Static Web Apps CLI. - -## Template Structure - -- **Client**: The Blazor WebAssembly sample application -- **Api**: A C# Azure Functions API, which the Blazor application will call -- **Shared**: A C# class library with a shared data model between the Blazor and Functions application - -## Deploy to Azure Static Web Apps - -This application can be deployed to [Azure Static Web Apps](https://docs.microsoft.com/azure/static-web-apps), to learn how, check out [our quickstart guide](https://aka.ms/blazor-swa/quickstart). +This is Bill Me App. From c27d5bcdecbcd1a01e49684446edd4de66be49d3 Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Sun, 6 Jul 2025 22:10:19 +0530 Subject: [PATCH 05/11] Pwa name updated --- Client/wwwroot/manifest.webmanifest | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/wwwroot/manifest.webmanifest b/Client/wwwroot/manifest.webmanifest index 00ba795..96edfce 100644 --- a/Client/wwwroot/manifest.webmanifest +++ b/Client/wwwroot/manifest.webmanifest @@ -1,6 +1,6 @@ { - "name": "BlazorApp15", - "short_name": "BlazorApp15", + "name": "BillMeApp", + "short_name": "BillMeApp", "id": "./", "start_url": "./", "display": "standalone", From 86520da61ae06592b660b89d4b0d5c04399969a1 Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Mon, 7 Jul 2025 09:37:45 +0530 Subject: [PATCH 06/11] Optimization Flags added --- Client/Client.csproj | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Client/Client.csproj b/Client/Client.csproj index 2578370..2f446ad 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -4,7 +4,15 @@ net8.0 enable enable - BlazorApp.Client + BlazorApp.Client + + + true + true + true + true + true + none @@ -12,9 +20,8 @@ - - + From 25dd1b6e998c56c2a328f8be7a38adebe186c1cf Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Mon, 7 Jul 2025 10:10:53 +0530 Subject: [PATCH 07/11] AOT removed. --- Client/Client.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Client/Client.csproj b/Client/Client.csproj index 2f446ad..b4743cb 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -7,10 +7,9 @@ BlazorApp.Client - true + true true - true true none From 457bcb935c466e25ff4674069b41dad829987245 Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Mon, 7 Jul 2025 10:17:41 +0530 Subject: [PATCH 08/11] Code optimization --- Client/Client.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Client/Client.csproj b/Client/Client.csproj index b4743cb..5023c68 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -11,6 +11,8 @@ true true true + false + false none From 3261b07b5e915f9bafc81cee6a81a4aefd3fbf2c Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Mon, 7 Jul 2025 10:32:40 +0530 Subject: [PATCH 09/11] Code Optimization --- Client/staticwebapp.config.json | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Client/staticwebapp.config.json b/Client/staticwebapp.config.json index 4a1bb1f..9be612a 100644 --- a/Client/staticwebapp.config.json +++ b/Client/staticwebapp.config.json @@ -1,5 +1,12 @@ { - "navigationFallback": { - "rewrite": "/index.html" + "navigationFallback": { + "rewrite": "index.html" + }, + "responseOverrides": { + "/_framework": { + "headers": { + "Content-Encoding": "br" + } } -} \ No newline at end of file + } +} From c2e3677227b44a099c2235a0e38e6320f7543daa Mon Sep 17 00:00:00 2001 From: Chandradev819 Date: Mon, 7 Jul 2025 10:51:12 +0530 Subject: [PATCH 10/11] Code reverted back --- Client/staticwebapp.config.json | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Client/staticwebapp.config.json b/Client/staticwebapp.config.json index 9be612a..e094983 100644 --- a/Client/staticwebapp.config.json +++ b/Client/staticwebapp.config.json @@ -1,12 +1,5 @@ { "navigationFallback": { - "rewrite": "index.html" - }, - "responseOverrides": { - "/_framework": { - "headers": { - "Content-Encoding": "br" - } - } + "rewrite": "/index.html" } } From af23af55eedf9a844212b07cec1040482153649f Mon Sep 17 00:00:00 2001 From: Chandradev Date: Mon, 7 Jul 2025 11:36:51 +0530 Subject: [PATCH 11/11] Update azure-static-web-apps-orange-water-0badfae10.yml --- ...static-web-apps-orange-water-0badfae10.yml | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/azure-static-web-apps-orange-water-0badfae10.yml b/.github/workflows/azure-static-web-apps-orange-water-0badfae10.yml index 57aadcc..806b55c 100644 --- a/.github/workflows/azure-static-web-apps-orange-water-0badfae10.yml +++ b/.github/workflows/azure-static-web-apps-orange-water-0badfae10.yml @@ -15,31 +15,44 @@ jobs: runs-on: ubuntu-latest name: Build and Deploy Job steps: - - uses: actions/checkout@v3 + - name: Checkout Code + uses: actions/checkout@v3 with: submodules: true lfs: false - - name: Build And Deploy - id: builddeploy + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Restore Dependencies + run: dotnet restore ./Client/Client.csproj + + - name: Publish Blazor App with Brotli & Trimming + run: | + dotnet publish ./Client/Client.csproj \ + -c Release \ + -o build \ + -p:BlazorWebAssemblyEnableCompression=true \ + -p:PublishTrimmed=true + + - name: Deploy to Azure Static Web App uses: Azure/static-web-apps-deploy@v1 with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ORANGE_WATER_0BADFAE10 }} - repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) + repo_token: ${{ secrets.GITHUB_TOKEN }} action: "upload" - ###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### - # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig - app_location: "./Client" # App source code path - api_location: "Api" # Api source code path - optional - output_location: "wwwroot" # Built app content directory - optional - ###### End of Repository/Build Configurations ###### + app_location: "." # Root path — not used when using `output_location` + api_location: "Api" # Optional: Azure Function App folder (if any) + output_location: "build/wwwroot" # Pointing to the manually published output close_pull_request_job: if: github.event_name == 'pull_request' && github.event.action == 'closed' runs-on: ubuntu-latest name: Close Pull Request Job steps: - - name: Close Pull Request - id: closepullrequest + - name: Close Pull Request Preview uses: Azure/static-web-apps-deploy@v1 with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ORANGE_WATER_0BADFAE10 }}