Nextjs api route proxy logger #897
              
                
                  
                  
                    Answered
                  
                  by
                    chimurai
                  
              
          
                  
                    
                      popuguytheparrot
                    
                  
                
                  asked this question in
                Q&A
              
            -
| Hi. How to use with nextjs and logger all request and errors? // pages/api/gateway/[[...slug]].ts
import winston, {format, transports} from "winston";
export const logger = winston.createLogger({
  format: format.combine(format.splat(), format.simple()),
  transports: [new transports.Console()],
});
const proxy = createProxyMiddleware({
  target,
  changeOrigin: true,
  pathRewrite: { "^/api/": "" },
  secure: false,
  preserveHeaderKeyCase: true,
  xfwd: true,
  logger: logger,
});
export default (req, res) => {
 // what here???
} | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            chimurai
          
      
      
        Mar 29, 2023 
      
    
    Replies: 1 comment
-
| 
 You can find some examples here: | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        popuguytheparrot
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
loggeris a v3@beta functionality: #768.Make sure to have the correct version installed.
You can find some examples here:
NextJS: https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md#nextjs
log: https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md#log-request-and-response