Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log nuxt server side network requests?

Is there some way how to log all network requests which are done by nuxtjs on server side?

I'm already using node --inspect to enable chrome console, but network tab is missing there.

Thanks a lot for any tip.

like image 998
Martin Rázus Avatar asked Dec 17 '22 21:12

Martin Rázus


1 Answers

I'm using axios nuxt plugin (https://axios.nuxtjs.org).

I've created a plugin to extend it (https://axios.nuxtjs.org/extend.html):

export default ({$axios, store}) => {
  $axios.onResponse(response => {
    console.log(`[${response.status}] ${response.request.path}`);
  });

  $axios.onError(err => {
    console.log(`[${err.response && err.response.status}] ${err.response && err.response.request.path}`);
    console.log(err.response && err.response.data);
  })
}
  • onError() logs errored requests
  • onResponse() logs successfull requests

Here is a sample output:

[200] /dashboard/rights/user
[200] /dashboard/rights/segment
[200] /dashboard/user/me
[400] /group/entries?group_id=undefined
{ status: 'error',
  codeStatus: 400,
  detail:
   [ { message:
        '"group_id" with value "undefined" fails to match the valid object id pattern',
       path: 'group_id',
       type: 'string.regex.name' } ] }

Hope it helps

like image 92
Nicolas Perraut Avatar answered Jan 13 '23 15:01

Nicolas Perraut