Skip to main content

Azure

tip

Don't know what a handler is? See the Architecture section.

This is a implementation that will return a function that expect to receive the following arguments: context and event, respectively.

function(context, event) {...}

Requirements

First, install the types for this adapter:

npm i --save-dev @azure/[email protected]

Customize

By default we use log property inside Context as default logger for this library .

We detect when the log instance is created with createDefaultLogger and then replace this instance with the instance inside Context.

If you want to log using the original instance createDefaultLogger, you can set the useContextLogWhenInternalLogger option to false for AzureHandlerOptions.

import { AzureHandler } from '@h4ad/serverless-adapter/handlers/azure';

const handler = new AzureHandler({
useContextLogWhenInternalLogger: false,
});

Usage

First, you need to configure your function.json to be able to receive all requests from Azure.

function.json
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "{*segments}"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}

Then, you can import and call the method setHandler, as per the code below:

index.ts
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { AzureHandler } from '@h4ad/serverless-adapter/handlers/azure';
import { PromiseResolver } from '@h4ad/serverless-adapter/resolvers/promise';
import { HttpTriggerV4Adapter } from '@h4ad/serverless-adapter/adapters/azure';
import app from './app';

export default ServerlessAdapter.new(app)
.setHandler(new AzureHandler())
.setResolver(new PromiseResolver())
// continue to set the other options here.
// .setFramework(new ExpressFramework())
.addAdapter(new HttpTriggerV4Adapter())
.build();
caution

Be careful when exporting the handler because in azure you must export default and in DefaultHandler you must export const handler.

The above code will add support for Azure Http Trigger V4, to learn more about Http Trigger, see the adapter docs.

Attention

You MUST use PromiseResolver to integrate with AzureHandler, other resolvers didn't work with Azure.

Examples

You can see examples of how to use here.