DucHT
DucHT

Reputation: 391

How to do something before Nextjs getStaticProps execution, eg Interceptor?

I want to intercept and add common header properties to all request call in getStaticProps, getServerSideProps which is execute at serverside.

axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    // Ex: Add some common header props
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

Upvotes: 1

Views: 806

Answers (1)

yusung lee
yusung lee

Reputation: 366

I have the same issue as you.

I searched for lots but can't find any tiny solution.

Maybe make a custom Axios instance component.

And you can use import customAxios from '../customAxios' instead of import axios from "axios"

Upvotes: 1

Related Questions