text: import next from 'next';
  import express from 'express';
  import mongoose from 'mongoose';
  import graphqlHTTP from 'express-graphql';
  
  import root from './graphql/root';
  import schema from './graphql/schema';
  
  require('dotenv').config();
  mongoose.connect(process.env.MONGODB_URL, {useNewUrlParser: true, useUnifiedTopology: true});
  var db = mongoose.connection;
  db.on('error', console.error.bind(console, 'connection error:'));
  db.once('open', function(callback) {
      console.log(callback)
      console.log("connection to db open")
  });
  
  const port = process.env.PORT;
  const dev = process.env.NODE_ENV !== 'production'
  const app = next({ dev })
  const handle = app.getRequestHandler()
  
  
  app.prepare().then(() => {
    const server = express()
  
    server.get('/a', (req, res) => {
      return app.render(req, res, '/a', req.query)
    })
  
    server.use('/graphql', graphqlHTTP({
      schema: schema,
      rootValue: root,
      graphiql: true,
    }));
  
  
    server.all('*', (req, res) => {
      return handle(req, res)
    })
  
    server.listen(port, err => {
      if (err) throw err
      console.log(`> Ready on http://localhost:${port}`)
    })
  })
  