score:114
set https=true
before you run the start command.
the implementation uses the https environment variable to determine which protocol to use when starting the server.
score:0
https=true npm start
in the terminal worked for me on create-react-app
score:1
i could not get that to work (setting https=true), instead, i used
react-https-redirect
a simple wrapper around your app
component.
score:1
i am using windows 10 latest build with windows insider program till this date.
it seems like there are three cases while using windows 10:
- windows 10 with cmd command line for your npm
set https=true&&npm start
- windows 10 with powershell command line for your npm
set https=true&&npm start
- windows 10 with linux bash command line for your npm ( my case was this )
https=true npm start
documentation: create react app dev
score:1
to avoid untrusted certificate errors in chrome and safari you should manually specify a self-signed key pair. cra allows you to specify them.
also, use .env
file to store these vars.
on macos, just add your certificate to keychain access and then set trust always
in its details.
score:1
important point about this issue: if you are looking to use https on lan (rather than localhost) then ssl certification is an issue because the ip is not static!
this is a nice read on the subject where they explore the option of doing it anyway: ssl for devices in local networks
score:2
in windows environment add following lines to package.json:
"scripts": {
"start-dev": "set https=true&&set port=443&&react-scripts start"
},
it will start development server with https and port 443. at the present moment nodejs have known bug to run this correctly but it worked with nodejs v8.11.3 - https://nodejs.org/dist/v8.11.3/node-v8.11.3-x64.msi for me.
score:2
for windows, try this one
($env:https = "true") -and (npm start)
i am using vs code terminal (powershell).
score:2
add to file .env (or .env.local) line: https=true
score:3
might need to install self-signed ca chain on both server and browser. difference between self-signed ca and self-signed certificate
score:3
you can create a proxy.https->http
create a key and cert.
openssl req -nodes -new -x509 -keyout server.key -out server.cert
create a file named proxyserver.js
var httpproxy = require('http-proxy');
let fs = require('fs');
httpproxy.createserver({
target: {
host: 'localhost',
port: 3000
},
ssl: {
key: fs.readfilesync('server.key', 'utf8'),
cert: fs.readfilesync('server.cert', 'utf8')
}
}).listen(3000);
from the terminal run
node proxyserver.js
score:3
i`m using windows 10 and i had the same issue. i realized that you need to:
- run command prompt with administrator privileges
- run on the terminal bash this command:
set https=true&&npm start
you can also put this code into your package.json file under the scripts section like this:
"scripts": { "start": "set https=true&&react-scripts start", (...) }
bonus: if you want to change the port use this command insted:
set https=true&&set port=443&&react-scripts start
obs.: pay attention to the blank spaces not left in between some characters.
you can browse this link for more detais.
score:3
edit your package.json file and change the starting scripts for starting your secures domain. for example https
{
"name": "social-login",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-facebook-login": "^4.0.1",
"react-google-login": "^3.2.1",
"react-scripts": "1.1.4"
},
"scripts": {
// update this line "start": "https=true react-scripts start",
"start": "set https=true&&react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
thanks
score:4
if it's still not working properly because of "your connection is not private" issues (in chrome), this worked for me just fine:
https://github.com/facebook/create-react-app/issues/3441
in short:
- first i exported certificate from chrome (view this).
- imported the certificate into windows (using certmgr.msc).
- allowed chrome://flags/#allow-insecure-localhost flag. how to allow insecure localhost
score:5
please use this in command prompt
set https=true&&npm start
score:5
i think it is worth to mention to set port=443
, default https
standard port.
you can avoid to attach :port
at the end of the address when browsing every time.
su
export https=true
export port=443
export ssl_crt_file=/path/to/cert.pem # recommended
export ssl_key_file=/path/to/privkey.pem # recommended
npm start
or
you can put them all in to package.json
:
"scripts": {
"start": "https=true port=443 react-scripts start",
then, without export
ing:
su
npm start
score:7
"scripts": {
"start": "set https=true&&set port=443&&react-scripts start",
........
}
in case you need to change the port and set it to https.
score:13
set https=true&&react-scripts start
in scripts > start: of package.json as shown below.
"scripts" in package.json:
"scripts": {
"start": "set https=true&&react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
- please don't leave any space in between the commands i.e,
https=true && npm start
won't work.
refer it in official doc. using https in development
(note: the lack of whitespace is intentional.)
score:18
in case of mac/unix do
export https=true
npm start
or simple one liner
export https=true&&npm start
or update start script in package.json to
"start": "export https=true&&port=3000 react-scripts start",
you should be able to hit https.
score:19
windows (cmd.exe)
set https=true&&npm start
(note: the lack of whitespace is intentional.)
windows (powershell)
($env:https = "true") -and (npm start)
linux, macos (bash)
https=true npm start
note that the server will use a self-signed certificate, so your web browser will almost definitely display a warning upon accessing the page.
custom ssl certificate
https=true ssl_crt_file=<sslcert.crt> ssl_key_file=<sslcert.key> npm start
linux, macos (bash)
https=true ssl_crt_file=<sslcert.crt> ssl_key_file=<sslcert.key> npm start
to avoid doing it each time: you can include in the npm start script like so:
{
"start": "https=true react-scripts start"
}
or you can create a .env file with https=true
score:34
you can also create a file called .env in the root of your project, then write
https=true
after that, just run "npm start" as you usually do to start your app.
docs: https://facebook.github.io/create-react-app/docs/advanced-configuration
works both on linux and windows, unlike some other answers posted here.
score:42
you can edit your package.json scripts section to read:
"scripts": {
"start": "set https=true&&react-scripts start",
...
}
or just run set https=true&&npm start
just a sidenote, for me, making this change breaks hot reloading for some reason....
-- note: os === windows 10 64-bit
Source: stackoverflow.com
Related Query
- How to use yarn to create a React app project?
- how to use .env.qa or .env.staging with create react app
- How to avoid very long paths and use absolute paths within a Create React App project?
- How to use Turborepo for an existing react app created with Create React App in order to make it a monorepo?
- Starting a react app in HTTPS instead of HTTP
- How to use webpack devServer proxy in create react app
- How to use community HTTP plugin in a Ionic React app when running the app on Android Emulator?
- How to use Create react app to install React
- How to create a React app directly in the current folder
- create-react-app: how to use https instead of http?
- How to create multiple page app using react
- When to use a react framework such as Next or Gatsby vs Create React App
- How to not show warnings in Create React App
- How to use environment variables in React app hosted in Azure
- How to include custom JS files in to React create app
- How to inject port and host using ENV variable in Create React App Proxy settings?
- How to fix TypeError _interopRequireDefault is not a function in Create React App
- What's the easiest way to use Create React App with Relay?
- How to change PublicPath for Create React App in Dev Environment
- Heroku redirect Next.js React client app http to https
- How to analyze create react app build size and reduce it?
- How to read console.log from a mounted component with Enzyme and Jest in Create React App
- How to import a file into a react app that uses create react app as raw text?
- How to make React Create App Production Error Boundary map to source code
- How to create a React App without Create-react-app
- Create react app - how to copy pdf.worker.js file from pdfjs-dist/build to your project's output folder?
- How to create react app without git (skipping git)?
- How to use Tesseract.js in a React app
- How to make Semantic UI react Search use id instead of title as key
- how to config create react app with worker-loader
More Query from same tag
- In React - How to get value from .sh(Shell Script) file?
- nextJS: async getInitialProps() with AWS S3?
- IMAGE: You may need an appropriate loader to handle this file type
- Tooltip is not working inside the List properly
- Blank page on refresh when using nested path
- IE 11 react 'promise' is undefined
- How to handle user logged in state in React JS and Firebase?
- Guarantee the data retrieved from Firebase is not NULL
- How to get rid of Typescript type error when overriding MuiContainer classes?
- How to render a new page while using react-router
- Redux: Why making a shallow copy of one level of the state is a mistake?
- Redux, how to reuse reducer/actions?
- React hook useState method updates array unexpectedly
- Formatting using destructuring and Object.entries
- Any idea why Typescript behaves this way with Material UI Alert severity prop?
- React - How to prevent click event from child component
- How do I serve a React application from an Spring Boot application?
- Pass path Param to render() function of Route in Switch - React Router
- How can I use React with Google Places API, to display place markers on a Google map?
- how to properly format JSX in the new class (extends component) format
- Set local variable in method inside the html in reactjs
- Const does not Exist in React
- How to write a simple functional component that return a array list using map method
- Render a consumed API on Django to React Front-end
- QuerySelector in react-select
- yarn eg:'live-server' is not recognized as an internal or external command
- React rendering display wrong elements
- How to correctly use 'connect' in react-redux with Typescript
- How to synchronously change state within useState
- React custom event listener