node-fetchを使い,postを行いたいのですが、どうしてもcorsでエラーが出てしまいます。mode: corsはちゃんと付けています。
import axios from "axios"; import fetch from "node-fetch"; import { User } from "types/types"; export const fetch1 = async (type = "", user: User) => { const params = new FormData(); params.append("username", user["username"]); params.append("password", user["password"]); const response = await fetch( "https://hoge.herokuapp.com/api/works", { method: "POST", headers: { 'Access-Control-Allow-Origin':'*' }, body: params, mode: "cors", //credentials: "include", // cookieを付けたい場合い } ); console.log(response) const json = await response.json(); console.log(json); }; // Access to fetch at 'https://hoge.herokuapp.com/api/works' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Postmanを使って叩けていることは確認しています。解決策がわかる方はどうかよろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/18 14:17 編集
2020/06/17 05:25
2020/06/17 05:26
2020/06/17 05:28
2020/06/17 05:29