chrisleekr / yii2-angular-boilerplate

Yii2 REST API + Angular 12 Boilerplate (Frontend/Backend)

Home Page:https://yam-boilerplate.chrislee.kr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting No 'Access-Control-Allow-Origin' exception

dev7ch opened this issue · comments

Hey,

i really like what you are creating!

After installation and running npm start in backend directory i am not able to log in via http://localhost:4200/.

it throws:

Failed to load http://api.boilerplate.local/v1/setting/public: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

Do you have a hint what it could be?
Maybe routing in the yii2 api?

Hi @dev7ch,

Have you configured API as well?
Are you able to access http://api.boilerplate.local? If yes, can you send me what you see when you access http://api.boilerplate.local

Hi @chrisleekr,
thanks for your fast reply.

yes, i added http://api.boilerplate.local to my /etc/hosts as described in your very good documentation.

So, i am able to access the url in browser and just see my ~/Sites directory as i would enter localhost in the browser.

If i open http://localhost/yii2-angular4-boilerplate/api/web/in the broswer it shows me:

{"name":"Bad Request","message":"The system could not process your request. Please check and try again.","code":0,"status":400,"type":"yii\\web\\BadRequestHttpException"}

and at least a GET with my rest client as image below:

image

Hi @chrisleekr,
the error is resolved, some configurations on my local machine have been missing.

I needed to edit my virtual hosts configs and add the VirtualDocumentRoot and ServerName, e.g. at /private/etc/apache2/extras/httpd-vhost.conf.

<VirtualHost *:80>
  ServerName api.boilerplate.local
  VirtualDocumentRoot "/Users/silvan/Sites/yii2-angular4-boilerplate/api/web"
</VirtualHost>

Now all works fine as expected, thx 👍