I have configured my Nuxt (Node.js application) to run on Plesk. This means that Plesk will execute the server.js file, which in turn runs ExpressJS and then Nuxt. Here is the content of my server.js file:
const express = require('express')
const consola = require('consola')
const { Nuxt } = require('nuxt')
const app = express()
const port = process.env.PORT;
const config = require('./nuxt.config.js')
config.dev = process.env.NODE_ENV !== 'production'
async function start() {
const nuxt = new Nuxt(config)
const { host } = nuxt.options.server
const port = process.env.PORT;
await nuxt.ready()
app.use(nuxt.render)
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true,
})
}
start()
I am looking to serve Nuxt on sample.com/blog and serve a specific page at sample.com. How can I achieve this using ExpressJS or Plesk? I would prefer to use ExpressJS, but I am unsure how to proceed. Any help would be appreciated.
I have attempted to modify my server.js file with the code below, but it has not resolved the issue:
const express = require('express')
const consola = require('consola')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const config = require('./nuxt.config.js')
config.dev = process.env.NODE_ENV !== 'production'
async function start() {
const nuxt = new Nuxt(config)
const { host } = nuxt.options.server
const port = process.env.PORT;
await nuxt.ready()
app.use(nuxt.render)
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true,
})
}
app.get('/blog',(req,res)=>{
start()
})
app.get('/',(req,res)=>{
res.send('Hello World!')
})
app.listen(port, ()=>{
console.log(`Example app listening on port ${port}`)
})
Currently, sample.com displays 'Hello World', but sample.com/blog returns an error.