text: const config = require('./utils/config')
  const express = require('express')
  require('express-async-errors')
  const app = express()
  const cors = require('cors')
  const blogRouter = require('./controllers/blogRoutes')
  const usersRouter = require('./controllers/userRoutes')
  const loginRouter = require('./controllers/loginRoutes')
  const middleware = require('./utils/middleware')
  const logger = require('./utils/logger')
  const mongoose = require('mongoose')
  
  logger.info('connecting to', config.MONGODB_URI)
  
  mongoose.connect(config.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, useCreateIndex: true })
    .then(() => {
      logger.info('connected to MongoDB')
    })
    .catch((error) => {
      logger.error('error connecting to MongoDB:', error.message)
    })
  
  app.use(cors())
  app.use(express.static('build'))
  app.use(express.json())
  app.use(middleware.requestLogger)
  
  app.use(middleware.tokenExtractor)
  app.use('/api/blogs', blogRouter)
  app.use('/api/users', usersRouter)
  app.use('/api/login', loginRouter)
  
  if (process.env.NODE_ENV === 'test') {
    const testingRouter = require('./controllers/testRoute')
    app.use('/api/testing', testingRouter)
  }
  
  app.use(middleware.unknownEndpoint)
  app.use(middleware.errorHandler)
  
  module.exports = app