Deploy hapi.js v17 on app engine but always return 502

107 views
Skip to first unread message

robin...@gmail.com

unread,
Jun 19, 2018, 8:53:49 AM6/19/18
to Google App Engine
Hi guys, I'm currently deploying a simple hapi.js v17.x on App engine which is a hello word project. After i deployed it, i tried to get access to "/" which should have returned a hello work but it returned 502 status code instead (502 bad gateway). When I use hapi.js v16 it was deployed successfully tho.
The difference is that in v17 they use async function and in v16 they use callback. I will show you the code:

hapi v17 NOT WORKING (502 BAD gateway)
const Hapi = require('hapi');

// Create a server with a host and port
const server = Hapi.server({
   
port: 3000,
    host: '0.0.0.0'
});

server.route({
   
method: 'GET',
    path: '/',
    handler: (request, h) => {
       
return 'Hello, world!';
    }
});


const init = async () => {

     
await server.start();
     console.log(`Server running at: ${server.info.uri}`);
};


init();


V16 working fine: D
const Hapi = require('hapi');

// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
    host: '0.0.0.0',
    port: process.env.PORT || 8080
});

server.route({
    method: 'GET',
    path:'/',
    handler: (request, reply) => {
        reply('Hello World!');
    }
});

server.start(() => {
    console.log('Server running at:', server.info.uri);
});

I would like to know why in v17 they always return 502?

Jordan (Cloud Platform Support)

unread,
Jun 19, 2018, 7:25:07 PM6/19/18
to Google App Engine
It is required to listen on port 8080 as App Engine will route all 'appspot.com' requests to this port. If your application does not listen on port 8080, the nginx webserver in front of your application will return a 502 Bad Gateway error to the Load Balancer since it cannot connect to your application.

If you instead wish to use a different port, you must follow the Port Forwarding guide; note that this is only used for direct IP connections to an App Engine instance and will not change 'appspot.com' request behavior.

- Note that Google Groups is reserved for general product discussions and is not for technical support. For further technical support in getting your application code to run on App Engine, it is recommended to post your detailed questions to Stack Exchange using the supported Cloud tags. 
Reply all
Reply to author
Forward
0 new messages