text: const express = require('express');
  const helmet = require('helmet');
  const xss = require('xss-clean');
  const mongoSanitize = require('express-mongo-sanitize');
  const compression = require('compression');
  const cors = require('cors');
  const passport = require('passport');
  const httpStatus = require('http-status');
  const { jwtStrategy } = require('./config/passport');
  const routes = require('./routes/v1');
  const { errorConverter, errorHandler } = require('./middlewares/error');
  const ApiError = require('./utils/ApiError');
  const app = express();
  
  // set security HTTP headers
  app.use(helmet());
  
  // parse json request body
  app.use(express.json());
  
  // parse urlencoded request body
  app.use(express.urlencoded({ extended: true }));
  
  // sanitize request data
  app.use(xss());
  app.use(mongoSanitize());
  
  // gzip compression
  app.use(compression());
  
  // enable cors
  app.use(
    cors({
      origin: true,
      optionsSuccessStatus: 200,
      credentials: true,
    })
  );
  app.options(
    '*',
    cors({
      origin: true,
      optionsSuccessStatus: 200,
      credentials: true,
    })
  );
  
  // jwt authentication
  app.use(passport.initialize());
  passport.use('jwt', jwtStrategy);
  
  // v1 api routes
  app.use('/api/v1', routes);
  
  // send back a 404 error for any unknown api request
  app.use((req, res, next) => {
    next(new ApiError(httpStatus.NOT_FOUND, 'Not found'));
  });
  
  // convert error to ApiError, if needed
  app.use(errorConverter);
  
  // handle error
  app.use(errorHandler);
  
  module.exports = app;
  