Last active
November 8, 2017 20:40
-
-
Save dantenovski/489fd0641ed48ee4338eca8cc454a58f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // webpack | |
| presets: ['stage-0', 'es2015', 'react'] | |
| // saga fetch | |
| const { loginEmail, loginPwd } = request.payload; | |
| let postLoginSubmitOptions = { | |
| method: "POST", | |
| headers: new Headers({ | |
| 'Accept': 'application/json', | |
| 'Content-type': 'application/x-www-form-urlencoded' | |
| }), | |
| mode: 'no-cors', | |
| body: JSON.stringify({ | |
| loginEmail: "[email protected]", | |
| loginPwd: "passwordkdhfhf" | |
| }) | |
| }; | |
| console.log(postLoginSubmitOptions.body) // { "loginEmail" : "[email protected]", "loginPwd" : "passwordkdhfhf" } | |
| const response = yield call(fetch, `http://www.example.com/register`, postLoginSubmitOptions); | |
| // express server side | |
| router.post('/register', bodyParser.urlencoded({ extended: false }), function(req, res, next) { | |
| console.log('registering user'); | |
| res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3333'); | |
| res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); | |
| res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); | |
| res.setHeader('Access-Control-Allow-Credentials', true); | |
| console.log(`incoming req below`); | |
| console.log(req.body); // { '{ "loginEmail" : "[email protected]", "loginPwd" : "passwordkdhfhf" }' : '' } | |
| // app.js | |
| app.use(bodyParser.json()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment