当前位置: 首页 > 知识库问答 >
问题:

create-react-app:如何用https代替http?

黄丰
2023-03-14

我想知道是否有人知道如何在“创建-反应-应用”环境中使用https。我在自述文件或快速搜索中找不到任何相关信息。我只希望https://localhost:3000能够工作,或者https://localhost:3001能够工作。

共有3个答案

柴禄
2023-03-14

您还可以在项目的根目录中创建一个名为. env的文件,然后编写

HTTPS=true

之后,像往常一样运行“npm start”来启动您的应用程序。

文档:https://facebook.github.io/create-react-app/docs/advanced-configuration

在Linux和Windows上都能工作,不像这里张贴的其他一些答案。

广晔
2023-03-14

您可以编辑包。json脚本部分内容如下:

“脚本”: { “开始”: “设置 HTTPS=真

或者只运行setHTTPS=true

只是一个旁注,对我来说,由于某种原因,做这个改变打破热重装....

--注意:OS===Windows 10 64位

鲁鸿
2023-03-14

在运行start命令之前,设置HTTPS=true。

文档

该实现使用 HTTPS 环境变量来确定启动服务器时要使用的协议。

 类似资料:
  • Create React App 不用配置就可以创建 React App。 全局安装: npm install -g create-react-app 创建 App: create-react-app my-appcd my-app/ 启动 npm: npm start 打开 http://localhost:3000/  查看你的 App。 如果你准备将其部署到生产环境,只需创建一个压缩包,并且运行 npm run build。

  • Create React Native App The fastest way to create universal React Native apps npx create-react-native-app Once you're up and running with Create React Native App, visit this tutorial for more informat

  • Create React Redux App Structure Create React + Redux app structure with build configurations. What can I find here? Express, Cors React + Redux, ES6, async/await Web Components (Custom Elements) inte

  • create-react-app React Project with Node Express Backend Example on using create-react-app with a Node Express Backend Usage Install nodemon globally npm i nodemon -g Install server and client depende

  • 我使用create react应用程序已经有一段时间了。“npm start”或“yarn start”自动重装本身工作正常,但现在我有了另一个问题。目前,我在express server上通过build文件夹运行应用程序,我使用“npm run build ”,因为express正在提供构建文件。有许多api调用要求应用程序以这种方式运行。现在,每次手动执行“npm运行构建”变得很乏味。有没有一

  • 创建响应应用时,图像中出现错误。它一直在正常工作,我所做的就是mkdir和cd到那个dir。 这就是错误的样子... NPX:在36.634s中安装了99必须使用导入来加载ES模块: C:\用户\Neeraj\AppData\漫游\npm-cache_npx\5172\node_modules\create-react-app\node_modules\is-promise\index.js不支持