Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Cloud Deployment #344

Closed
John0x opened this issue Mar 4, 2017 · 9 comments
Closed

Google Cloud Deployment #344

John0x opened this issue Mar 4, 2017 · 9 comments
Labels

Comments

@John0x
Copy link

John0x commented Mar 4, 2017

Hey, I'm having issues to deploy my nuxt based application in the google cloud.
The logs are fine, but the website doesn't work at all.

Has anyone attempted to deploy nuxt to gcloud?

This question is available on Nuxt.js community (#c295)
@John0x John0x closed this as completed Mar 6, 2017
@tomasleiva9
Copy link

tomasleiva9 commented Mar 14, 2017

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?

@John0x
Copy link
Author

John0x commented Mar 15, 2017

@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:

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

@tomasleiva9
Copy link

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

@sqram
Copy link

sqram commented Jan 20, 2018

Adding on to here that, even after disabling health check, i still get

502 Bad Gateway
nginx

not sure what the cause is

@ghost
Copy link

ghost commented Feb 12, 2018

@sqram Did you set the port 8080 (app engines uses that port)

@dudenk
Copy link

dudenk commented Mar 8, 2018

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

@sqram
Copy link

sqram commented Mar 9, 2018

@Reworking i did. i tried many other things as well. Eventually gave up and went fully restful :(

@lilianaziolek
Copy link

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 :(

@lock
Copy link

lock bot commented Nov 2, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 2, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants