text: import express from 'express';
  import dotenv from 'dotenv';
  import webpack from 'webpack';
  import helmet from 'helmet';
  import axios from 'axios';
  import passport from 'passport';
  import boom from '@hapi/boom';
  import cookieParser from 'cookie-parser';
  
  import main from './routes/main';
  
  const { config } = require('./config/index');
  
  dotenv.config();
  
  const ENV = process.env.NODE_ENV;
  const app = express();
  const PORT = process.env.PORT || 3000;
  
  app.use(express.json());
  app.use(cookieParser());
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(express.static(`${__dirname}/public`));
  
  if (ENV === 'development') {
    console.log('Loading dev config');
    // eslint-disable-next-line global-require
    const webpackConfig = require('../../webpack.config');
    // eslint-disable-next-line global-require, import/no-extraneous-dependencies
    const webpackDevMiddleware = require('webpack-dev-middleware');
    // eslint-disable-next-line global-require, import/no-extraneous-dependencies
    const webpackHotMiddleware = require('webpack-hot-middleware');
    const compiler = webpack(webpackConfig);
    const serverConfig = {
      contentBase: `http://localhost${PORT}`,
      port: PORT,
      publicPath: webpackConfig.output.publicPath,
      hot: true,
      historyApiFallback: true,
      stats: { colors: true },
    };
    app.use(webpackDevMiddleware(compiler, serverConfig));
    app.use(webpackHotMiddleware(compiler));
  } else {
    console.log(`Loading ${ENV} config`);
    app.use(helmet());
    app.use(helmet.permittedCrossDomainPolicies());
    app.disable('x-powered-by');
  }
  
  //  Basic strategy
  require('./utils/auth/strategies/basic');
  // OAuth strategy
  // require('./utils/auth/strategies/oauth');
  // Twitter strategy
  // require('./utils/auth/strategies/twitter');
  
  app.post('/auth/sign-in', async (req, res, next) => {
    passport.authenticate('basic', (error, data) => {
      try {
        if (error || !data) {
          next(boom.unauthorized());
        }
  
        req.login(data, { session: false }, async (error) => {
          if (error) {
            next(error);
          }
  
          const { token, ...user } = data;
  
          res.cookie('token', token, {
            httpOnly: !(ENV === 'development'),
            secure: !(ENV === 'development'),
          });
  
          res.status(200).json(user);
        });
      } catch (error) {
        next(error);
      }
    })(req, res, next);
  });
  
  app.post('/auth/sign-up', async (req, res, next) => {
  
    console.log('/auth/sign-up');
  
    const { body: user } = req;
    console.log('axios complete');
  
    console.log(`${config.apiUrl}/api/auth/sign-up`);
  
    try {
      await axios({
        url: `${config.apiUrl}/api/auth/sign-up`,
        method: 'post',
        data: user,
      });
      res.status(201).json({ message: 'user created' });
    } catch (error) {
      next(error);
    }
  });
  
  app.get('*', main);
  
  app.listen(PORT, (err) => {
    if (err) console.log(err);
    console.log(`Listening http://localhost:${PORT}`);
  });
  
  