Socket
Socket
Sign inDemoInstall

react-ssl-redirect

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-ssl-redirect

Redirect to HTTP to HTTPS


Version published
Weekly downloads
1
Maintainers
1
Install size
3.31 kB
Created
Weekly downloads
 

Readme

Source

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")
);



Keywords

FAQs

Last updated on 16 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc