GithubHelp home page GithubHelp logo

chthomos / azure-function-express Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zeyuri/azure-function-express

0.0 0.0 0.0 512 KB

⚡️Allows Express.js usage with Azure Functions

License: Apache License 2.0

JavaScript 100.00%

azure-function-express's Introduction

fork of azure-function-express from Hapticmedia

Tested and working with express 4.17.1 and Node 14 (LTS) and Functions Runtime v3

Summary of changes

  • Fixed deprectation warning for req._headers (now uses getHeaders())
  • Fixed problem with unpipe
Supported by Hapticmedia

azure-function-express

Function logo

Allows Express usage with Azure Function

npm version Node Node Travis Status Coverage Status MIT licensed

Description

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

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 12
  • Node 14 (LTS)

Azure Functions runtime v3 is supported.

License

Apache 2.0 © Yves Merlicco

azure-function-express's People

Contributors

yvele avatar harrythomos avatar zeyuri avatar christensena avatar cyrusnajmabadi avatar cloudify avatar nevercast avatar maktwin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.