|
1 | 1 | # Angular Template Hierarchy and Data fetching Example |
2 | 2 |
|
3 | | -In this example we show how to implement the WordPress Template Hierarchy in Angular for use with a Headless WordPress backend using WPGraphQL. |
| 3 | +In this example we show how to implement the **WordPress Template Hierarchy in Angular** for use with a Headless WordPress backend using WPGraphQL. |
4 | 4 |
|
5 | | -## Getting Started |
| 5 | +## Getting Started 🚀 |
6 | 6 |
|
7 | 7 | > [!IMPORTANT] |
8 | | -> Docker Desktop needs to be installed to run WordPress locally. |
| 8 | +> **Docker Desktop** needs to be installed to run WordPress locally. |
9 | 9 |
|
10 | 10 | 1. Run `npm run example:setup` to install dependencies and configure the local WP server. |
11 | | -2. Run `npm run backend:start` starts the backend server for template fetching at http://localhost:3000/api/templates |
12 | | -3. Run `npm run example:start` to start the WordPress server and Angular development server. |
| 11 | +2. **Configure CORS:** Create a file named **`.env`** inside the **`/backend`** directory and add the following content to set the allowed frontend URL: |
| 12 | + ``` |
| 13 | + FRONTEND_URL=http://localhost:4200 |
| 14 | + ``` |
| 15 | + *(For more details on the backend service, please refer to the **`/backend/README.md`** file.)* |
| 16 | +3. Run `npm run backend:start` starts the backend server for template fetching at **http://localhost:3000/api/templates** |
| 17 | +4. Run `npm run example:start` to start the WordPress server and Angular development server. |
13 | 18 |
|
14 | 19 | > [!NOTE] |
15 | 20 | > When you kill the long running process this will not shutdown the local WP instance, only Angular. You must run `npm run example:stop` to kill the local WP server. |
16 | 21 |
|
17 | | -## Trouble Shooting |
| 22 | +## Trouble Shooting 🛠️ |
| 23 | +
|
18 | 24 | 1. I get "Page Not Found. Sorry, the page you are looking for does not exist. Please check the URL." when opening the Angular app and trying to navigate through it. |
19 | | -- Run `npm run backend:start` and verify that http://localhost:3000/api/templates returns correct data. |
20 | | -- Verify if you have added `/backend/.env` file with correct `FRONTEND_URL`. |
21 | | -- check for any errors in the console |
22 | | -2. In some cases, you might have to install @angluar/cli globally. In /example-app/ run `npm install -g @angular/cli@latest` |
| 25 | +- Run `npm run backend:start` and verify that **http://localhost:3000/api/templates** returns correct data. |
| 26 | +- **Verify that you have created the `/backend/.env` file with the correct `FRONTEND_URL`** to resolve CORS issues. |
| 27 | +- Check for any errors in the console. |
| 28 | +2. In some cases, you might have to install **`@angular/cli`** globally. In `/example-app/` run `npm install -g @angular/cli@latest` |
23 | 29 | 3. To reset the WP server and re-run setup you can run `npm run example:prune` and confirm "Yes" at any prompts. |
0 commit comments