Run BFF Locally
To run both the app and BFF locally, ports must be configured correctly since both default to using ports 3000 and 4200. Follow the steps below to modify the BFF ports.
Steps
-
Locate the BFF Entry in the
.envFile
Find the relevant BFF entry in the.envfile for the desired market. Example:NEXT_PUBLIC_MY_BFF_API_URLinapps/example.com/us/.env. -
Update the URL Port
Modify the URL to use an unused port, e.g.,http://localhost:4201. -
Open
project.jsonin the BFF Project Root
Navigate to the root of the BFF project and openproject.json. -
Modify the
serveandserve-baseOptions- The
serve-baseoption serves the Next.js app by default. - The
serveoption performs the same function with SSL enabled.
- The
-
Update the
serveConfiguration
Add the following properties insideserve:"serve": { "options": { "serveTarget": "my-bff-us-web:serve-base", "targetPort": 4201, "port": 3001 } } -
Update the
serve-baseConfiguration
Add the following properties insideserve-base:"serve-base": { "options": { "buildTarget": "my-bff-us-web:build", "dev": true, "port": 4201 } } -
Run the BFF Locally
Execute the following command to start the BFF:nx run my-bff-us-web:serve