Next.js - Error: only absolute urls are supported

后端 未结 6 1185
感动是毒
感动是毒 2020-12-29 10:05

I\'m using express as my custom server for next.js. Everything is fine, when I click the products to the list of products

Step 1: I click the produc

6条回答
  •  感动是毒
    2020-12-29 10:17

    This simple solution worked for me without having to add an additional config file,

    Install

    npm install --save next-absolute-url
    

    Usage

    import absoluteUrl from "next-absolute-url";
    
    async getInitialProps({ req }){
      const { origin } = absoluteUrl(req, req.headers.host);
      console.log('Requested URL ->',origin); 
      // (or) other way
      const host = absoluteUrl(req, req.headers.host);
      console.log('Requested URL ->',host.origin); 
    }
    

提交回复
热议问题