Static GitHub Issues

[2811] How can I run both dev and production servers in the same time?

prev: Provide/Inject example
next: Optimization

If I start the production server I get no errors in chrome console, but after I start the same server but in development mode I get a lot of 404 errors in chrome console probably because the dev server builds some files again. How can I run both in the same time without the dev server changing production server files?

My server script:

const https = require('https')
const fs = require('fs')
const express = require('express')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const host = process.env.HOST || 'localhost' //127.0.0.1
var port = process.env.PORT || 2096
var cluster = require('cluster')
var os      = require('os')
var num_processes = os.cpus().length

// Import and Set Nuxt.js options
let config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
if(config.dev) {
  num_processes = 1;
}

const options = {
    key: fs.readFileSync('/server/ssl/cert.key'),
    cert: fs.readFileSync('/server/ssl/cert.crt')
}

if (cluster.isMaster) {  
  // This stores our workers. We need to keep them to be able to reference
  // them based on source IP address. It's also useful for auto-restart,
  // for example.
  var workers = [];

  // Helper function for spawning worker at index 'i'.
  var spawn = function(i) {
    workers[i] = cluster.fork();

    // Optional: Restart worker on exit
    workers[i].on('exit', function(code, signal) {
      logger.info('Respawning worker.');
      spawn(i);
    });
  };

  // Spawn workers.
  for (var i = 0; i < num_processes; i++) {
    spawn(i);
  }
} else {
  async function start() {
    // Init Nuxt.js
    const nuxt = new Nuxt(config)

    // Build only in dev mode
    if (config.dev) {
      const builder = new Builder(nuxt)
      await builder.build()
        .then(listen)
        .catch((error) => {
          console.error(error)
          process.exit(1)
        })
    } else {
      listen()
    }

    function listen() {
      // Listen the server
      https
        .createServer(options, nuxt.render)
        .listen(port)
      console.log('Server listening on https://' + host + ':' + port) // eslint-disable-line no-console
    }
  }
  start()
}

And the chrome console after I start the dev server: 47be1b60e3c44d6d884c6a15865908c9

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2437">#c2437</a>)</em></sub></div>