简体   繁体   English

可以在 reactjs 中使用 https 运行 serve -s build

[英]can run serve -s build with https in reactjs

I need to run "serve -s build" with https in reactjs application.我需要在 reactjs 应用程序中使用 https 运行“serve -s build”。

Try to run HTTPS with Npm and it is worked fine but when run production build using"serve -s build" the production run with HTTP not HTTPS.尝试使用 Npm 运行 HTTPS,它运行良好,但是当使用“serve -s build”运行生产构建时,生产运行使用 HTTP 而不是 HTTPS。

serve -s build服务 -s 构建

Try using serve-https instead. 尝试改为使用serve-https

And if you are testing it in localhost in the Google Chrome you can enalble Allow invalid certificates for resources loaded from localhost. 而且,如果您正在Google Chrome的localhost中对其进行测试,则可以启用“ Allow invalid certificates for resources loaded from localhost. in chrome://flags/ chrome://flags/

You must pass ssl information and the switch operate automatically.您必须传递 ssl 信息,开关会自动运行。

openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
# Fill all prompted demands, "127.0.0.1" as "Common name" is OK for development environment
serve -s build --ssl-cert cert.pem --ssl-key key.pem

See also也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM