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







No comments: