...
This commit is contained in:
parent
35bd66f21f
commit
8ab76adbe6
146 changed files with 101 additions and 40 deletions
|
|
@ -0,0 +1,54 @@
|
|||
https://codeigniter.com/user_guide/libraries/cors.html
|
||||
|
||||
app/Config/Filters.php
|
||||
```php
|
||||
public array $filters = [
|
||||
// ...
|
||||
'cors' => [
|
||||
'before' => ['api/*'],
|
||||
'after' => ['api/*'],
|
||||
],
|
||||
];
|
||||
|
||||
```
|
||||
|
||||
app/Config/Routes.php
|
||||
```php
|
||||
// API routes (put below service('auth'))
|
||||
|
||||
// For Cors preflight check
|
||||
$routes->group('', ['filter' => 'cors'], static function (RouteCollection $routes) {
|
||||
$routes->options('api/(:any)', static function () {});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
$routes->group("api", ["filter" => "cors", "namespace" => "App\Controllers\Api"], function($routes) {
|
||||
$routes->post("register", "AuthController::register");
|
||||
$routes->post("login", "AuthController::login", ["filter"=>"cors"]);
|
||||
$routes->get("profile", "AuthController::profile");
|
||||
$routes->get("logout", "AuthController::logout", ["filter"=>"apiauth"]);
|
||||
|
||||
$routes->get("invalid-access", "AuthController::accessDenied");
|
||||
|
||||
$routes->get("test2" , "AuthController::test2");
|
||||
|
||||
# WORKS
|
||||
$routes->get("test" , "TestController::test");
|
||||
//$routes->post("add-project", "ProjectController::addProject");
|
||||
//$routes->get("list-projects", "ProjectController::listProjects");
|
||||
//$routes->delete("delete-project/(:num)", "ProjectController::deleteProject/$1");
|
||||
});
|
||||
```
|
||||
|
||||
app/Config/Cors.php
|
||||
```php
|
||||
|
||||
'allowedOrigins' => ['*'],
|
||||
'allowedOriginsPatterns' => ['http://.*','https://.*'],
|
||||
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
|
||||
'allowedHeaders' => ['*'],
|
||||
'maxAge' => 7200,
|
||||
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue