- Forums
- react
- Run Https Secured Ssl Url On A React Application With Vitejs
This page will show you what you need to do to run your local server as secured ssl https mkcert [5066], Last Updated: Sat Jan 21, 2023
dd
Sat Jan 21, 2023
0 Comments
25 Visits
During development, sometimes its necessary to run a local environment with HTTPS to test an API. This happened today to me, I was running a local React application on http:localhost/3000 and the backend api was giving me CORS errors. This was because the protocols did not match with my Fronend React App and my backed API>
To fix it:
- Install vite-plugin-mkcert
$ npm i vite-plugin-mkcert -D
- Open file vite.config.js
- Add the following
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import mkcert from 'vite-plugin-mkcert'
// https://stackoverflow.com/a/71618444
// https://vitejs.dev/config/
export default defineConfig({
server: { https: true },
plugins: [react(),mkcert()],
base: '/'
})
- Start the server
$ npm run dev