通常previewでアクセスした場合はapiにアクセスできましたが、
unityでビルドしたWebGLのアプリを
localhostに表示させ
そのアプリから別ドメインに設置したrubyのapiで通信したところ
以下エラーが表示されました。
OPTIONS http://hogeserver/api/authcreate 404 (Not Found) (index):1 XMLHttpRequest cannot load http://hogeserver/api/authcreate. 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:49504' is therefore not allowed access. The response had HTTP status code 404.
別ドメインに設置したrubyのapiは自分のもので、
nginx-unicornサーバの上で動いてます。
XMLHttpRequest cannot load nginxで検索したところAllow-Origin
を追加すると良いとあったので、
nginxにaddの部分を追加しました。
server { listen 80; server_name test.hogeserver; root /~/public; # add start add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Headers' 'Content-Type,Accept'; add_header 'Access-Control-Allow-Method' 'GET, POST, OPTIONS, PUT, DELETE'; # add end
nginxとunicornを再起動した後でも、
表題のエラーが消えませんでした。
あなたの回答
tips
プレビュー