npm install cookies-next
- Need to add following environment variables to your
NextJS App
NEXT_PUBLIC_API_URL=your_api_url
NEXT_PUBLIC_API_TOKEN=your_api_token
- Create a file named
setup.js
at root folder (or anywhere in you project) - Copy following code and paste into the file
const {initApiInstance, generateApiRoutes} = require('wph-proxy-next');
initApiInstance(process.env.NEXT_PUBLIC_API_URL, process.env.NEXT_PUBLIC_API_TOKEN);
generateApiRoutes(path.join(__dirname, "your-target-directory"));
- Add a custom script to
package.json
to executesetup.js
file
For example:
"start": "node setup.js"
- Run this script before you build your
NextJS App
to populate api handlers