InsidersByte/honeymoon-gift-list

View on GitHub
server/routes/index.js

Summary

Maintainability
A
0 mins
Test Coverage
const environmentConstants = require('../constants/environment');
const path = require('path');
const api = require('./api');

module.exports = ({ app, express, config, environment }) => {
  const apiRoutes = api({ express, config });

  app.use('/api', apiRoutes);

  if (environment === environmentConstants.PRODUCTION) {
    app.get('*', (req, res) => {
      res.set('Content-Type', 'text/html');
      res.sendFile(path.join(__dirname, '../../', 'build/index.html'));
    });
  } else {
    const middleware = app.get('middleware');

    app.get('*', (req, res) => {
      res.set('Content-Type', 'text/html');
      res.write(middleware.fileSystem.readFileSync(path.join(__dirname, '../../', 'build/index.html')));
      res.end();
    });
  }
};