I'm having the same issue. I'm deploying with gcloud and after update completes the page shows the error 502
Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.
That's happining with the "starter" template, with no modifications.
What I'm doing wrong?
@tomasleiva9 The app engine has an integrated health check feature, which asks your service periodically whether its alive or not.
Using the nuxt cli for starting won't be enough, you have to use the express middleware to be able to add a new endpoint for the health check.
This is my code for the express server:
````javascript
const Nuxt = require('nuxt')
const app = require('express')()
const host = process.env.HOST || '0.0.0.0'
const port = process.env.PORT || 8080
app.set('port', port)
// Import and Set Nuxt.js options
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
// GCloud Health Check
app.get('/_ah/health', (req, res) => {
res.status(200)
res.send()
})
// Init Nuxt.js
const nuxt = new Nuxt(config)
app.use(nuxt.render)
// Build only in dev mode
if (config.dev) {
nuxt.build()
.catch((error) => {
console.error(error) // eslint-disable-line no-console
process.exit(1)
})
}
// Development error handler
if (app.get('env') === 'development') {
app.use((err, req, res) => {
res.status(err.status || 500)
res.render('error', {
message: err.message,
error: err
})
})
}
// Production error handler
app.use((err, req, res) => {
console.log(err)
res.status(err.status || 500)
res.render('error', {
message: err.message,
error: {}
})
})
// Listen the server
app.listen(port, host)
console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console
````
Perfect @John0x . It worked very well.
Thanks.
I found more information about this in documentation from Vuejs, if someone else need more help...
https://nuxtjs.org/api/configuration-dev
Adding on to here that, even after disabling health check, i still get
502 Bad Gateway
nginx
not sure what the cause is
@sqram Did you set the port 8080 (app engines uses that port)
hello @John0x
i copy your script and found error
/app/server.js:19
const nuxt = new Nuxt(config)
^
TypeError: Nuxt is not a constructor
at Object.<anonymous> (/app/server.js:19:14)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
@reworking i did. i tried many other things as well. Eventually gave up and went fully restful :(
Would someone here be so kind and post a github link to a full working project (i.e. where you can clone, yarn, and run gcloud app deploy and it works) ? I tried applying numerous solutions from here and stack overflow on top of the simplest project from template https://github.com/nuxt-community/express-template and still cannot get it to work :(
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@tomasleiva9 The app engine has an integrated health check feature, which asks your service periodically whether its alive or not.
Using the nuxt cli for starting won't be enough, you have to use the express middleware to be able to add a new endpoint for the health check.
This is my code for the express server:
````javascript
const Nuxt = require('nuxt')
const app = require('express')()
const host = process.env.HOST || '0.0.0.0'
const port = process.env.PORT || 8080
app.set('port', port)
// Import and Set Nuxt.js options
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
// GCloud Health Check
app.get('/_ah/health', (req, res) => {
res.status(200)
res.send()
})
// Init Nuxt.js
const nuxt = new Nuxt(config)
app.use(nuxt.render)
// Build only in dev mode
if (config.dev) {
nuxt.build()
.catch((error) => {
console.error(error) // eslint-disable-line no-console
process.exit(1)
})
}
// Development error handler
if (app.get('env') === 'development') {
app.use((err, req, res) => {
res.status(err.status || 500)
res.render('error', {
message: err.message,
error: err
})
})
}
// Production error handler
app.use((err, req, res) => {
console.log(err)
res.status(err.status || 500)
res.render('error', {
message: err.message,
error: {}
})
})
// Listen the server
app.listen(port, host)
console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console
````