Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. var app = express();
  2.  
  3. app.use(function(req, res, next) {
  4. res.header('Access-Control-Allow-Credentials', true);
  5. res.header('Access-Control-Allow-Origin', req.headers.origin);
  6. res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  7. res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
  8. if ('OPTIONS' == req.method) {
  9. res.send(200);
  10. } else {
  11. next();
  12. }
  13. });
  14.  
  15. export function* login() {
  16. const username = yield select(makeSelectUsername());
  17. const password = yield select(makeSelectPassword());
  18.  
  19. const requestURL = 'http://myurlhere.com:1337/user/login/';
  20.  
  21. const requestOptions = {
  22. method: 'POST',
  23. mode: 'cors',
  24. headers: {
  25. 'Accept': 'application/json',
  26. 'Content-Type': 'application/json'
  27. },
  28. body: JSON.stringify(
  29. {username: username,
  30. password: password}
  31. )
  32. }
  33.  
  34. try {
  35. const result = yield call(request, requestURL, requestOptions);
  36.  
  37. yield put(loginApiCallSuccess(result));
  38. } catch (err) {
  39. yield put(loginApiCallFailure(err));
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement