New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

redux-http-status

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-http-status

Redux reducer and action to set http status in the store for use server side. Comes with bundled react components

latest
Source
npmnpm
Version
0.0.11
Version published
Maintainers
1
Created
Source

redux-http-status

This library provides a simple http status handling when using react, redux, react-redux, react-router and react-router-redux.

It's composed of :

A reducer


import { httpStatusReducer } from 'redux-http-status'

export default combineReducers({
  ...otherReducers,
  status: httpStatusReducer,
})

A NotFound react component

import { NotFound } from 'redux-http-status'

export default function NotFoundPage() {
  return (
    <NotFound>
      This page was not found
    </NotFound>
  )
}

A Forbidden component

Which works like NotFound

A Redirect component

  <Route
    path="/old/date"
    component={() => <Redirect code={301} url="/date" />}
  />

Server usage

To make it work server side, here's a Koa exemple that renders an App, sets the status and redirect if needed.:

koaze.router.get('/*', ctx => {
  const history = createMemoryHistory({ initialEntries: [ctx.url] })
  const store = createStore(
    reducers,
    compose(applyMiddleware(routerMiddleware(history), thunk))
  )

  // Render app
  const app = renderToString(
    <Root store={store} history={history}>
      <App />
    </Root>
  )
  // Get status from redux store
  const { status } = store.getState()
  ctx.status = status.code

  if ([301, 302].includes(status.code)) {
    ctx.redirect(status.url)
    return
  }

  ctx.type = 'text/html'
  ctx.body = renderHtml(app, store)
})

FAQs

Package last updated on 01 Mar 2018

Did you know?

Socket

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