content: import { match, RouterContext } from 'react-router'
  import _ from 'lodash'
  import environment from '~/server/services/environment'
  import express from 'express'
  import minifyHTML from 'express-minify-html'
  import { renderToString } from 'react-dom/server'
  import React from 'react'
  import routes from '~/app/router'
  
  // eslint-disable-next-line new-cap
  const router = express.Router()
  
  if (!environment.isDebug()) {
    router.use(minifyHTML({
      'override': true,
      'htmlMinifier': {
        'removeComments': true,
        'collapseWhitespace': true,
        'collapseBooleanAttributes': true,
        'removeAttributeQuotes': true,
        'removeEmptyAttributes': true,
        'minifyJS': true,
        'processScripts': ['application/ld+json']
      }
    }))
  }
  
  // React Controller that works with the react's router in the app directory
  router.get('*', (req, res) => {
    match({
      routes,
      'location': req.url
    }, (error, redirect, props) => {
      // Handle the different kind of response depending if we face an error,
      // a redirect or a successful request.
      if (error) {
        return res.status(500).send(error.message)
      } else if (redirect) {
        return res.redirect(302, redirect.pathname + redirect.search)
      } else if (props) {
        // Default status is 200
        let status = 200
  
        // Render the router context to string and store it in the locals
        // so we can then insert it in the view
        res.locals.reactContent = renderToString(<RouterContext {...props}/>)
  
        // Should we override the default status?
        if (_.get(props, 'routes[1].status')) {
          // Look in the router tag for a status attribute
          status = parseInt(_.get(props, 'routes[1].status'), 10)
        }
  
        // Render the view
        return res.status(status).render('index.html')
      }
  
      res.status(404).render('index.html')
    })
  })
  
  export default router
  