DEV Community

Cover image for Run React App Localhost in Https in 2 steps
Krushna Chandra Dash
Krushna Chandra Dash

Posted on

6

Run React App Localhost in Https in 2 steps

Question->
How do I use the React development server to serve requests from https while working on localhost?

Ex ->https://localhost:3000

Advantages of using Httpsin 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.


Enter fullscreen mode Exit fullscreen mode

For React App Created with Vite


Step-1

1.Install vite-plugin-mkcert package.

Step-2

  1. 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
  }

})


Enter fullscreen mode Exit fullscreen mode

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

  1. Modify start script in package.json and it should look like this


    "start": "cross-env HTTPS=true react-scripts start",



Enter fullscreen mode Exit fullscreen mode

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
Run React App Localhost in Https in 2 steps

then click on advancebutton and click on continue to site.

Run React App Localhost in Https in 2 steps

.. Happy coding..

if this article helps please don't forget to Share with other..

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay