clivend clivend - 16 days ago 6
Javascript Question

Hapi js and Postman Chrome App - subsequent requests

I have this very minimal hapi server:

const Hapi = require('hapi');
const server = new Hapi.Server();

server.connection({
port: 8080
});

server.route({
method: 'GET',
path: '/hello',
handler: function(request, reply) {

console.log('hooray');
setTimeout(function() {
console.log('mellow');
return reply("Hello");
}, 7500);//7.5 seconds
}
});

server.start((err) => {
console.log(`Server started at ${ server.info.uri }`);
});


Now if send 2 request with a 2 seconds delay using Postman Chrome App (from 2 different tabs), I get this output on the console:

Server started at http://clivend-N56VV:8080
hooray
mellow
hooray
mellow


Why is hapi waiting to reply to first request before processing the other?

Thanks!

Answer

It's not hapi that is waiting for the prevoius request. I bet you are testing it in one browser. Try to make 2 request from 2 different browsers or with curl.