0

I have NodeJS app in azure functions where I use "azure functions express" module. There is no method context.done() in this module. And 302 redirects every time return empty body with 200 status code. Redirection works with context.done() method for example see Azure Functions Redirect Header

How can I implement context.done() or smth like that to work with redirections.

Thank you!!!!

1 Answers1

0

Since the idea behind the module seems to be to use express APIs themselves, I believe you could just call res.redirect(<url>) as required.

I've tested it with the following settings

  1. HttpTrigger/index.js
const createHandler = require("azure-function-express").createHandler;
const express = require("express");

// Create express app as usual
const app = express();

app.get("/api/", (req, res) => {
  res.redirect('/api/abc/xyz');
});

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);
  1. HttpTrigger/function.json
{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ],
      "route": "api/{*segments}"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}
  1. host.json
{
    "version":  "2.0",
    "extensions": {
      "http": {
        "routePrefix": ""
      }
    }
}
PramodValavala
  • 6,026
  • 1
  • 11
  • 30