enabling cors in codeigniter ( restserver by @chriskacerguis )

后端 未结 6 719
鱼传尺愫
鱼传尺愫 2020-12-03 12:38

http.get request in agularJs controller works fine when my client app and api are in localhost. when api is moved to server., issue arised.

client side using angular

6条回答
  •  攒了一身酷
    2020-12-03 13:16

    If anyone else is facing the issue, enabling CORS in rest.php file of Codeigniter REST Controller worked for me. This is also clearly documented in comments here https://github.com/chriskacerguis/codeigniter-restserver/blob/master/application/config/rest.php

    //Change this to TRUE
    $config['check_cors'] = TRUE;
    
    //No change here
    $config['allowed_cors_headers'] = [
      'Origin',
      'X-Requested-With',
      'Content-Type',
      'Accept',
      'Access-Control-Request-Method',
      'Authorization',
    ];
    
    //No change here
    $config['allowed_cors_methods'] = [
      'GET',
      'POST',
      'OPTIONS',
      'PUT',
      'PATCH',
      'DELETE'
    ];
    
    //Set to TRUE to enable Cross-Origin Resource Sharing (CORS) from any source domain
    $config['allow_any_cors_domain'] = TRUE;
    
    
    //Used if $config['check_cors'] is set to TRUE and $config['allow_any_cors_domain'] is set to FALSE. 
    //Set all the allowable domains within the array
    //e.g. $config['allowed_origins'] =['http://www.example.com','https://spa.example.com']
    
    $config['allowed_cors_origins'] = [];
    

提交回复
热议问题