So I figured I'll answer this question as I had searched for a while and found nothing.
Scenario (Angular frontend and Strapi backend):
I have blog posts that contain text and images, and I am trying to display the images on my website as they are stored in markdown on strapi.
example of what the image path in markdown looks like

The problem is that on the frontend, this path resolves to
http://localhost:4200/uploads/beautiful_picture.jpg
whereas the image is actually here
http://localhost:1337/uploads/beautiful_picture.jpg
How can I configure my angular frontend app to use the strapi backend URL when creating image URLs without having to manually copy the backend uploads folder into my frontend src folder?
To resolve this issue, I had to use Angular proxy, note that this can be used for both local and remote servers.
For example, to divert all calls for http://localhost:4200/uploads to your backend strapi server running on http://localhost:1337/uploads, take the following steps.
Create a file proxy.conf.json in your project's src/ folder.
Add the following content to the new proxy file:
{
"/uploads": {
"target": "http://localhost:1337",
"secure": false
}
}
angular.json, add the proxyConfig option to the serve target:...
"architect": {
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "frontend:build:production"
},
"development": {
"browserTarget": "frontend:build:development",
"proxyConfig": "src/proxy.conf.json"
}
},
...
Make sure to stop the development server if it's already running and type ng serve to boot up the dev server again.
Back in your browser, you should now see the images displayed within the text.
Visit Angular proxy to read more.
bonus tip: you can use ngx-markdown to display markdown content in your angular template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With