react-ssl-redirect

1.1.0 • Public • Published

react-ssl-redirect

redirect react-app to SSL version.

description

This is a simple javascript function and it should work for any javascript app including react, angular, vanilla javascript, vue, or any other js library.

install

npm install react-ssl-redirect

Usage

if you're using react, simply add it to your src/index prior to calling any other function or component.


import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import App from "./app";
// Redux
import { Provider } from "react-redux";
import store from "./redux/store";
// Setup
import axios from "axios";
import dotenv from "dotenv";
import ReactSSLRedirect from "react-ssl-redirect";

ReactSSLRedirect(); // <------ will redirect as soon as page is loaded.
dotenv.config();
axios.defaults.baseURL = process.env.REACT_APP_SERVER;
ReactDOM.render(
  <Provider store={store}>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </Provider>,
  document.querySelector("#root")
);



exceptions

by default, this package skip hostname that equals to "localhost". This means, if you are on localhost, you will not be redirected. If you want overide this, you may add the following argument.

{
    exceptions: ["hostname_to_skip"]
}

redirect_to

by default, you will be redirected to https version of your platform. For example, http://www.google.com, will be redirected to https://www.google.com

if you want to overide this. You must include the following:

{
    redirect_to: "https://www.different_link.com"
}

Exmaple


import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import App from "./app";
// Redux
import { Provider } from "react-redux";
import store from "./redux/store";
// Setup
import axios from "axios";
import dotenv from "dotenv";
import ReactSSLRedirect from "react-ssl-redirect";

ReactSSLRedirect({
    exceptions: ["localhost", "dev"],
    redirect_to: "https://www.somewhere.com"
});

dotenv.config();
axios.defaults.baseURL = process.env.REACT_APP_SERVER;
ReactDOM.render(
  <Provider store={store}>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </Provider>,
  document.querySelector("#root")
);



Readme

Keywords

Package Sidebar

Install

npm i react-ssl-redirect

Weekly Downloads

13

Version

1.1.0

License

ISC

Unpacked Size

3.39 kB

Total Files

3

Last publish

Collaborators

  • zwazoe