I have an angular service that has a GET request with params currentPage
and postsPerPage
. I'm trying to pass the parameters to an azure function and I'm following a tutorial which tells me to configure proxies.
if I use the this url which is provided when I run func start
}>(`http://localhost:7071/api/GetListingsWithPagination/`, { params })
then I can hit the endpoint and the error is currentPage is undefined
. Which is fine because I'm not passing currentPage
with proxy.
So moving on to configuring proxy:
with this configuration I have my angular service
using this endpoint in angular service
}>(`https://[sitename].azurewebsites.net/api/listings/${postsPerPage}/${currentPage}`, { params })
but it's returning
401 unauthorized
in browser console and never outputs in azure function console.
How can I get my params to work?
angular service
getWins(bidderId: string, currentPage: number, listingRoute: string) {
const postsPerPage = 10;
const queryParams = postsPerPage + "/" + currentPage;
const params = new HttpParams()
.set("bidderId", bidderId)
.set("listingRoute", listingRoute);
return this.http
.get<{
message: string;
posts: any;
maxPosts: number;
activeBidsList: string;
}>(`https://[sitename].azurewebsites.net/api/listings/${postsPerPage}/${currentPage}`, { params })
.pipe(
map(retrievedData => {
return {
posts: retrievedData.posts.map(post => {
return {
title: post.title,
startingBid: post.startingBid,
increments: post.increments,
shippingCost: post.shippingCost,
bidderId: post.bidderId,
id: post._id
};
}),
maxPosts: retrievedData.maxPosts
};
})
);
}
azure function
var MongoClient = require('mongodb').MongoClient;
//var Post = require('./model/post');
module.exports = function (context, req) {
MongoClient.connect(process.env.CosmosDBConnectionString, (err, client) => {
let send = response(client, context);
if (err) send(500, err.message);
console.log("DBNAME: " + process.env.dbName);
let db = client.db(process.env.dbName);
let params = ({ currentPage, postsPerPage } = req.params);
let postPerPage = +params.postPerPage;
let currentPage = params.currentPage;
console.log(postsPerPage);
console.log(currentPage);
return;
});
}