title: Express Route and Nextjs: app.render doesn't work in router file
body: <p>My server file started to get a little too long, so I decided to use express routing and split each route on a separate script. I did everything as usual but the problem is: app render method does not work and the page just keeps scrolling.
  This is what the index file looks like:</p>
  <pre><code>const express = require('express');
  const router = express.Router();
  const Declaration = require(&quot;../models/declaration&quot;)
  const next = require('next')
  const app = next({ true })
  
  router.get('/', async (req, res) =&gt;
  {
      const declarations = await Declaration.find({})
      app.render(req, res, &quot;/&quot;, { declarations })
  })
  router.post('/', async (req, res) =&gt;
  {
      const declaration = new Declaration({ ...req.body })
      await declaration.save();
      res.redirect(&quot;/&quot;)
  })
  
  module.exports = router;
  </code></pre>
  <p>Server file:</p>
  <pre><code>...
  
  const index = require(&quot;./routes/index&quot;)
  
  
  app.prepare().then(() =&gt;
  {
      const server = express();
  
      server.use(express.urlencoded({ extended: true }));
      server.use(methodOverride('_method'));
      server.use(express.static(path.join(__dirname, 'public')));
      server.use('/', index)
  
      ...
  
  </code></pre>
  <p>This is what the routes looked like before updating:</p>
  <pre><code>...
  app.prepare().then(() =&gt;
  {
      const server = express();
  
      server.use(express.urlencoded({ extended: true }));
      server.use(methodOverride('_method'));
      server.use(express.static(path.join(__dirname, 'public')));
  
       server.get(&quot;/&quot;, async (req, res) =&gt;
       {
           const declarations = await Declaration.find({})
           app.render(req, res, &quot;/&quot;, { declarations })
       })
      server.post(&quot;/&quot;, async (req, res) =&gt;
      {
          const declaration = new Declaration({ ...req.body })
          await declaration.save();
          res.redirect(&quot;/&quot;)
      })
      
  ...
  
  </code></pre>
  <p>I have really no ideea how to fix this.</p>