Question->
How do I use the React development server to serve requests from https while working on localhost?
Advantages of using Https
in localhost
1. Access to 3rd party API's without CORS error.
2. Working with cookies made easy.
3. Accessing Google and Facebook API's without deploying the
application.
For React App Created with Vite
Step-1
1.Install vite-plugin-mkcert package.
Step-2
- Change in
vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import mkcert from 'vite-plugin-mkcert'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(),mkcert()],
server:{
port:3000,
https: true
}
})
and then start your application with npm run dev
For React App Created with create-react-app
Step-1
1.Install cross-env package.
Step-2
- Modify start script in package.json and it should look like this
"start": "cross-env HTTPS=true react-scripts start",
and Done .. Now Run your app using npm start
.
if you get any package issue plese install all the package again using npm install
or yarn install
If facing any issue in browser like this
then click on advance
button and click on continue to site
.
.. Happy coding..
if this article helps please don't forget to Share with other..
Top comments (0)