CORS in CodeIgniter 4, the easy way, defining development URLs - 12
Let's learn how we can configure a URL in the cors.
Let's learn how we can configure a URL in the cors.
As an interesting task or at least to know a little more as I was telling you this is quite dangerous if we are going to go to production since you are indicating that anyone can connect and that may not be what you want unless it is an open one from some service in that case it would be an asterisk anyway remember that if we remove this then we automatically get the alert that tells us who found the origin due to the CORS protection that I mentioned before, we can change this aterisk to also place the URL so what you would have to do is copy the URL:
public\index.php
header('Access-Control-Allow-Origin: http://localhost:5173');
From the application that is going to consume this API or is going to connect to your CodeIgniter 4 through the API and we place it here, remove this last Slash:
http://localhost:5173/
Important if not it does not take it it is simply like that the base URL without the last Slash and there you also have to leave what is the port that may vary I think it changes now every time we start the application as I told you in development it is not necessary to do this but I think it is interesting to do it as far as I know you cannot define multiple URLs because it would be like placing them by commas or an array I do not know what can be done that way So we would be tied to only one route, a URL that could connect to our application, then well it was as I told you a simple demonstration I simply wanted to mention it there so that you had it in mind and without further ado let's move on to the next class.
- Andrés Cruz
This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y Libro CodeIgniter 4 desde cero + integración con Bootstrap 4 o 5 - 2025.
Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter
I agree to receive announcements of interest about this Blog.
!Courses from!
10$
On Udemy
There are 1d 13:40!
!Courses from!
4$
In Academy
View courses!Books from!
1$
View books