Azure SWA Function response is incorrect when Azure Table storage called

32 Views Asked by At

I have an api in an Azure SWA which needs to retrieve data from Azure Table Storage.

I am running local development using VSCode on an M1 MAC w/ the Function and SWA extensions, a dev-container, with Docker configure to use Rosetta.

The function returns static data correctly. The response has the correct content-type and payload. Even calling .listEntities on a Table Client will cause the response to have a plain/text content type and empty payload. Any ideas?

uncommenting the three lines in listEntities will cause the response to be empty.

const client = new TableClient(`https://${account}.table.core.windows.net`,
    tableName,sharedKeyCredential);

const good = [{id:3,value:"foo"}];

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
    listEntities()
        .then(e => {
            context.res = {
                status: 200,
                headers: {'Content-Type': 'application/json'},
                body: {info:e}             };
        });
};

async function listEntities(): Promise<any[]> {
//     for await (const entity of client.listEntities()) {
//         console.log("working");
//    };
    return good;
}

export default httpTrigger;
1

There are 1 best solutions below

0
On

Turns out I was missing the return in the trigger function. Should be returning the Promise, not just invoking the chain.

 ...
 const httpTrigger: AzureFunction = async function (context: Context, req: 
    HttpRequest): Promise<void> {
       return listEntities()
          .then(e => {
 ...