Socket
Socket
Sign inDemoInstall

@morning-bird/azure-function-express

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @morning-bird/azure-function-express

Allows Express usage with Azure Function


Version published
Maintainers
1
Install size
28.0 kB
Created

Readme

Source

azure-function-express

Function logo

npm version Node Node .github/workflows/verify.yaml Apache 2.0

Connect your Express application to an Azure Function handler, and make seamless usage of all middlewares you are already familiar with.

This is a fork of azure-fuction-express which appears to be abandoned.

Usage

In your index.js:

const createHandler = require("azure-function-express").createHandler;
const express = require("express");

// Create express app as usual
const app = express();
app.get("/api/:foo/:bar", (req, res) => {
  res.json({
    foo  : req.params.foo,
    bar  : req.params.bar
  });
});

// Binds the express app to an Azure Function handler
module.exports = createHandler(app);

Make sure you are binding req and res in your function.json:

{
  "bindings": [{
    "authLevel" : "anonymous",
    "type"      : "httpTrigger",
    "direction" : "in",
    "name"      : "req",
    "route"     : "foo/{bar}/{id}"
  }, {
    "type"      : "http",
    "direction" : "out",
    "name"      : "res"
  }]
}

To allow Express handles all HTTP routes itself you may set a glob star route in a single root function.json:

{
  "bindings": [{
    "authLevel" : "anonymous",
    "type"      : "httpTrigger",
    "direction" : "in",
    "name"      : "req",
    "route"     : "{*segments}"
  }, {
    "type"      : "http",
    "direction" : "out",
    "name"      : "res"
  }]
}

Note that segments is not used and could be anything. See Azure Function documentation.

All examples here.

Context

All native Azure Functions context properties, except done, are exposed through req.context.

As en example, you can log using:

app.get("/api/hello-world", (req, res) => {
  req.context.log({ hello: "world" });
  ...
});

Runtime compatibility

Supported Node version are Node 8 through to 16.

Azure Functions runtime v1 (with Node 8), v2 and v3 are supported. v4 is currently untested.

License

Keywords

FAQs

Last updated on 25 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc