Invoke function from ntl dev on port 80

My tik2.netlify.app is used on localhost with ntl dev -p 80.
How can I ntl functions:invoke foo for port 80 instead of standard port?
Current behaviour: Ran into an error invoking your function: request to http://localhost:8888/.netlify/functions/mongo?op=find&coll=sys failed, reason: connect ECONNREFUSED ::1:8888

Hi @tik9

If you are working on macOS, or Linux, you’ll likely have Apache installed which will use port 80—this is after all the standard HTTP port. This is why development tools use other ports—e.g. 8080, 8888, 3000.

Running ntl dev -p 80 on macOS results in

% ntl dev -o -p 80
◈ Netlify Dev ◈
◈ Ignored general context env var: LANG (defined in process)
◈ No app server detected. Using simple static server
◈ Running static server from "test-project/site"
◈ Could not acquire required 'port': '80'

It can’t acquire it because Apache is using it.

Much the same running functions:invoke

% ntl functions:invoke --port 80
? Pick a function to trigger main
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

This HTML page is the default 404 page for Apache because the function is running on the default port.

1 Like

Hello @tik9, thanks for posting.
In addition to @coelmay’s suggestion, you can also configure the functions port in the netlify.toml file in your project root with the content below.

[dev]
	functionsPort = 80

Hope this helps.

No, @clarnx his did not work in Netflify.toml. Same error as above. Where did you find the docs for it?
@coelmay I checked before with curl localhost if port 80 is free - and yes it is… But you helped with --port which works. You should add also -p as short flag similar to ntl dev -p. Thanks again, we close it.

If you run ntl <command> --help (e.g. ntl dev --help or ntl deploy --help) you’ll find further information about the long and short options available.

Hello @tik9 , thanks for the extra feedback.

1 Like

@coelmay if you read the docs, you notice that -p is for payload and not port with functions:invoke. Another thing: If I do ntl functions:invoke myfun --querystring 'a=b' I expect a get server request. But I get a post request which is not what I want: Request from ::1: POST /.netlify/functions/mongo?coll=sys. How is that? From the browser using fetch and get I get a get one. And from cli, the event.body is {} with a get, which is not correct. It should be undefined with a get as it is in the browser`s fetch. Maybe you should check this with a dev although it does not result in an error Just what I observed.

I know that.

I do not know.

As I am a community member (not a Netlify employee) I have no greater access to the CLI development team that you. If you believe the behaviour you are experiencing is incorrect I suggest filing an issue

3 Likes