Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable azure function https easily when do local test

I want to test Azure Function Http trigger locally on windows.

I use azure-function-core-tools to run command like func start --port 5007 --useHttps

And then I got error : Auto cert generation is currently not working on the .NET Core build.

It seems like that I should use command like func start --port 5007 --useHttps --cert certificate.pfx after I creating a self-signed certificate locally.

If there is a way to enable https easily?

The way like when I use .net core webapi, I easily export env:ASPNETCORE_URLS=https://localhost. And after clicking some button, I can use https well. Do we have some thing like this?

Or if func start --port 5007 --useHttps is enough but i miss some configuration?

Thank you!

like image 541
south Avatar asked Dec 18 '22 13:12

south


1 Answers

Update Answer:

func start --port 5007 --useHttps will not automatic create certificate after azure function v1. azure function v2 and azure function v3 tools which is based on .Net Core will not create certificate for you. You should generate the certificate manully.

Original Answer:

I can reproduce your error:

enter image description here

Solution:

Use administrator to start your powershell, go to your function app folder, and then use this command:

$cert = New-SelfSignedCertificate -Subject localhost -DnsName localhost -FriendlyName "Functions Development" -KeyUsage DigitalSignature -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")

And then create the certificate file:

Export-PfxCertificate -Cert $cert -FilePath certificate.pfx -Password (ConvertTo-SecureString -String 123 -Force -AsPlainText)

At last, I can use https:(below command runs in windows cmd.)

func host start --port 5007 --useHttps --cors * --cert certificate.pfx --password 123

enter image description here

like image 166
Cindy Pau Avatar answered Dec 20 '22 02:12

Cindy Pau