File size: 530 Bytes
3206347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import morgan from 'morgan';
import logger from './logger.js';

const stream = {
  write: (message) =>
    logger.http(message.substring(0, message.lastIndexOf('\n'))),
};

const registerGraphQLToken = () => {
  morgan.token('graphql-query', (req) => {
    if (req.body.query) {
      return `\n GraphQL ${req.body.query}`;
    }
  });
};

registerGraphQLToken();

const morganMiddleware = morgan(
  ':method :url :status :res[content-length] - :response-time ms :graphql-query',
  { stream }
);

export default morganMiddleware;