If you build an application with create-react-app and run it locally, the application will be served using the HTTP protocol by default. Applications running in a production environment are served using HTTPS. Although configuring HTTPS is pretty straightforward, configuring it locally is a bit more complicated.
As we all know, the create-react-app program is run with npm run start (or simply npm start). In the scripts section of the package.json file, there is a line of configuration:
Change it to:
Set the value of the environment variable HTTPS to true. This is not enough, you also need to generate a local certificate. Note: The following commands are executed on macOS, and can be operated in the same way on Linux. However, there is no guarantee that they will work successfully on Windows. In the project root directory, run:
Then run:
Two files, cert.pem and key.pem, will be generated in the current directory. Now change the start script in the package.json file to:
Now run npm run start and access the React application. You should see the following warning message: This is because the default browser does not trust the local certificate. Click on the little "Not Secure" icon near the address bar and a small panel will appear: Click on Certificate and you will see another panel with the certificate details: Now drag the certificate icon to the desktop or a folder with the mouse, and you will get the certificate file. Then double-click the certificate to install it and set it as "Trusted Certificate or Issuing Authority". After the setup is complete, you can access your React application locally via HTTPS: |
<<: Huawei's Ryan Ding: Working together to create the most successful 5G
We participated in the preheating and received co...
Today I will share with you some knowledge about ...
The CCBN-BDF Forum was held at the same time as t...
Recently, He Yide, the "naked running boy&qu...
To further accelerate its goal of deploying priva...
Usually, you may encounter such a phenomenon duri...
[51CTO.com original article] Since the outbreak o...
UK regulator Ofcom has revealed that so far in 20...
At the 7th Asia-Pacific Spectrum Management Confe...
5G is a hot topic - along with Web3.0 and the Met...
[[434629]] I didn't expect that in 2021, ther...
Last time we shared the news of V.PS Hong Kong ne...
It is time for operators to release their monthly...
Over the years, we've dutifully upgraded our ...