0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

フロントエンドとバックエンドを同時に開発している際の CORS 問題を解消する

Posted at

はじめに

研究で使用するプロトタイプを React.js と NestJS を使用して開発していた際、CORS が発生して大変だったので共有しておきます。

結論

"proxy": "設定したい URL"package.json にプロキシ設定を記述すると解決できます。

package.json
{
  ... ,
  "proxy": "http://localhost:4000"
}

と記述すると fetch などでリクエストを投げる際に http://localhost:4000/api/v1/ の代わりに /api/v1/ で実行が可能になります。

まとめ

CORS で悩まされて、毎回ものすごく困っていたので機能を見つけたとき感動しました。
初歩的な問題で知っている方も多いと思いますが、少しでも参考になればと思います。

参考文献

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?