Tuesday, November 25, 2025

Top Ways to Mock your server for testing/building Angular Project

 #1. Using Proxy 


Add a file proxy.conf.json

{

  "/rest": {
    "target": "http://tca-test-ems.tca.local:8080",
    "secure": false,
    "changeOrigin": true,
    "logLevel": "debug",
     "headers": {
      "Authorization": "Basic ZW1zdmljcm06OTclb3BzY2sh"
      }
    }
}

Run angular CLI using ng serve --proxy-config proxy.conf.json



#2. Exposing a brand-new Node Server Fake API:

Install
npm install -g json-server

Add a folder "server" and add two files : server.js and db.json
const app = require('express')();

app.get('/tier2/malfunctionPortalServiceApi/getIapsListForUser', (req, res) => {
  res.json([
    { id: 1, name: 'Node Mock IAP' }
  ]);
});
app.listen(3000);

Run that server. js in a new powershell window in VS Code







Wednesday, November 5, 2025

Powershell script to get Keyvault token using Powershell - Windows and Linux

 $os = [System.Environment]::OSVersion.Platform

$runningLinux = $false


$Host.UI.WriteLine("Running on $os")


if("Unix" -eq $os)

{

    $runningLinux = $true

}

az login --service-principal   -u <principle-guid>   -p <active-secret>   --tenant <token-guid>

$Host.UI.WriteLine("Login was successful for az cli and now going to get the token from https://vault.azure.net")

$token=az account get-access-token --resource https://vault.azure.net --query accessToken -o tsv


$Host.UI.WriteLine("Received token successful $token")

 

# Define headers properly (PowerShell expects a hash table)

$headers = @{

    "Authorization" = "Bearer $token"

}

 

$Host.UI.WriteLine("Start calling nslook on kvdmpprodae001.vault.azure.net")

if(!$runningLinux)

{

    Resolve-DnsName kvdmpprodae001.vault.azure.net

} else

{

    nslookup kvdmpprodae001.vault.azure.net

}

$Host.UI.WriteLine("End calling nslook on kvdmpprodae001.vault.azure.net")


$Host.UI.WriteLine("Start calling curl on https://kvdmpprodae001.vault.azure.net")

curl -v https://kvdmpprodae001.vault.azure.net

$Host.UI.WriteLine("End calling curl on https://kvdmpprodae001.vault.azure.net")

 

if($runningLinux)

{

    $Host.UI.WriteLine("Start calling curl on https://kvdmpprodae001.vault.azure.net/secrets/<your-key-name>?api-version=7.3")

    curl -v -H "Authorization: Bearer $token" --trace-ascii trace.log https://kvdmpprodae001.vault.azure.net/secrets/<your-key-name>?api-version=7.3

    $Host.UI.WriteLine("End calling curl on https://kvdmpprodae001.vault.azure.net/secrets/<your-key-name>?api-version=7.3")

}

 

# Call Key Vault REST API


$Host.UI.WriteLine("Invoking the webrequest with the token received")

$response = Invoke-WebRequest -Uri "https://kvdmpprodae001.vault.azure.net/secrets/<your-key-name>?api-version=7.3" -Headers $headers

 

    $Host.UI.WriteLine("Now printing the vault access")

# Output response

$response.Content



Once you created above .ps1 file. Run it using Powershell in Windows or install powershell in Linux and run using :

pwsh <filename>.ps1