Advertisement
rodro1

origin cors error laravel api

Oct 15th, 2019
1,911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public /index.php
  2. ========
  3.  
  4. add in top
  5. =======
  6. $allowedOrigins = array(
  7. 'http://localhost:600', // Laravel API Domain
  8. 'http://localhost:3000' // VueJS CLient
  9. );
  10. if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] != '') {
  11. foreach ($allowedOrigins as $allowedOrigin) {
  12. if (preg_match('#' . $allowedOrigin . '#', $_SERVER['HTTP_ORIGIN'])) {
  13. header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
  14. header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
  15. header('Access-Control-Max-Age: 1000');
  16. header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
  17. break;
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement