Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

func new httpTrigger seems to have wrong parameter order #3354

Open
lobunto opened this issue May 2, 2023 · 2 comments
Open

func new httpTrigger seems to have wrong parameter order #3354

lobunto opened this issue May 2, 2023 · 2 comments

Comments

@lobunto
Copy link

lobunto commented May 2, 2023

The handler-function arguments for httpTrigger functions seem to be in the wrong order when creating a new httpTrigger function.

When I run the func new command (locally in a terminal) and select httpTrigger as the function type, a file with this content is generated:

const { app } = require('@azure/functions');

app.http('httpTrigger', {
  methods: ['GET', 'POST'],
  authLevel: 'anonymous',
  handler: async (request, context) => {
    context.log(`Http function processed request for url "${request.url}"`);

    const name = request.query.get('name') || (await request.text()) || 'world';

    return { body: `Hello, ${name}!` };
  },
});

If I run the function with func start, the function throws this error to the console and gives me a 500 error in the browser:

Screenshot 2023-05-02 at 15 18 52

After changing the order of the arguments from the handler function to have context first and request as second (handler: async (context, request)), my function works as expected.

Is this a known issue?

@lobunto lobunto changed the title New httpTrigger function seems to have wrong parameter order func new httpTrigger seems to have wrong parameter order May 2, 2023
@ejizba
Copy link
Contributor

ejizba commented May 2, 2023

The template is correct. My guess is you are on an old version of the npm package. Can you make sure you're on @azure/functions v4.0.0-alpha.9 or greater?

More info:

@anddoutoi
Copy link

anddoutoi commented Jun 13, 2023

I just created a new function project by running:

func init api --worker-runtime node --language javascript --model V4

The package.json created looks like this:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "src/functions/*.js",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },
  "dependencies": {
    "@azure/functions": "^4.0.0-alpha.1"
  },
  "devDependencies": {
    "azure-functions-core-tools": "^4.x"
  }
}

and @azure/[email protected] is installed.

Using this preset and creating a function by running:

cd api

followed by:

func new --name "my-endpoint" --template "HTTP trigger"

creates a "legacy" handler with the wrong signature.

TL;DR: The dependency ^4.0.0-alpha.1 should probably be updated to the latest to avoid differences between JS and TS function projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants