Closed Dindaleon closed 8 years ago
Do you know it's the same request and not two requests? Can you log the request id?
I dont know if this helps or not, this is the output of request.getLog
first request:
[ { request: '1453154298763:My-PC:10504:ijkijpii:10000',
timestamp: 1453154298766,
tags: [ 'received' ],
data:
{ method: 'get',
url: '/home',
agent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36' },
internal: true },
{ request: '1453154298763:My-PC:10504:ijkijpii:10000',
timestamp: 1453154300378,
tags: [ 'handler', 'error' ],
data: { msec: 203.54270800948143, error: 'Not Found', data: [Object] },
internal: true } ]
second request:
[ { request: '1453154300491:My-PC:10504:ijkijpii:10001',
timestamp: 1453154300492,
tags: [ 'received' ],
data:
{ method: 'get',
url: '/api/v1/oauth/token',
agent: 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' },
internal: true },
{ request: '1453154300491:My-PC:10504:ijkijpii:10001',
timestamp: 1453154300497,
tags: [ 'handler' ],
data: { msec: 1.190521001815796 },
internal: true } ]
Oh! now I see. I am making two requests on load, one for rendering the page, in this case Home
, and the other request is for checking a user's credentials.
Is this acceptable or should I look for a way to improve it? Maybe having api calls on another connection?
I don't understand your problem.
My problem is that server rendering is happening twice. After you told me to check the number of requests and their ids, I could verify that there were two requests being made indeed. So it is not an issue of hapi. Then, I just asked if it was ok to have two or more requests on the same connection or if it is better to split them into two connections were the main connection is used for rendering the website and the other connection for api calls.
Are you trying to render only some routes and serve json on others? You can set ext on specific routes or check a flag in the ext for some endpoints. There are many patterns.This would be better raised in hapijs/discuss.
Yes, there is another route that serves json only. I will raise my issue on hapijs/discuss, no problem. Thank you.
Hello, I wonder what might be causing my
onPreResponse
hook to be called twice when rendering?This is my server file: