index.js 782 B

12345678910111213141516171819202122232425262728293031323334
  1. const express = require('express')
  2. const consola = require('consola')
  3. const { Nuxt, Builder } = require('nuxt')
  4. const app = express()
  5. const host = process.env.HOST || '127.0.0.1'
  6. const port = process.env.PORT || 3004
  7. app.set('port', port)
  8. // Import and Set Nuxt.js options
  9. let config = require('../nuxt.config.js')
  10. config.dev = !(process.env.NODE_ENV === 'production')
  11. async function start() {
  12. // Init Nuxt.js
  13. const nuxt = new Nuxt(config)
  14. // Build only in dev mode
  15. if (config.dev) {
  16. const builder = new Builder(nuxt)
  17. await builder.build()
  18. }
  19. // Give nuxt middleware to express
  20. app.use(nuxt.render)
  21. // Listen the server
  22. app.listen(port, host)
  23. consola.ready({
  24. message: `Server listening on http://${host}:${port}`,
  25. badge: true
  26. })
  27. }
  28. start()