Advertisement
Guest User

CORS Proxy

a guest
May 19th, 2019
3,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. 1) In package.json adaugi   "proxy": "http://localhost:5000", -> portu il pui pe care il folosesti tu pt https
  2. 2) Dai npm start
  3. 3) Exemplu de request :
  4. getLoginData = () => {
  5.     const config = {
  6.       mode: "no-cors",
  7.       headers: {
  8.         "Access-Control-Allow-Origin": "*",
  9.         "Access-Control-Allow-Methods": "GET,POST,PUT,DELETE",
  10.         "Content-Type": "application/json"
  11.       },
  12.       withCredentials: true,
  13.       credentials: "same-origin"
  14.     };
  15.  
  16.     this.setState({ isLoading: true });
  17.     axios
  18.       .post(
  19.         "/api/staff/login",
  20.         {
  21.           Username: this.state.username,
  22.           Password: this.state.password
  23.         },
  24.         config
  25.       )
  26.       .then(response => {
  27.         console.table(response.data);
  28.         this.props.setAuthData(response);
  29.         this.checkLogin();
  30.         this.setState({ isLoading: false });
  31.       })
  32.       .catch(() => {
  33.         console.log("Error");
  34.         this.setState({ isLoading: false });
  35.         this.checkLogin();
  36.       });
  37.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement