Guest User

Untitled

a guest
Nov 19th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. axios.interceptors.request.use((req) => {
  2. req.headers.authorization = `Bearer: ${MYTOKEN}`;
  3. return req;
  4. });
  5.  
  6. const router = express.Router();
  7.  
  8. router.use(function timeLog(req, res, next) {
  9. console.log(req.headers.authorization); // undefined :(
  10. })
  11.  
  12. { host: 'localhost:5000',
  13. connection: 'keep-alive',
  14. 'access-control-request-method': 'POST',
  15. origin: 'http://localhost:8080',
  16. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
  17. 'access-control-request-headers': 'authorization,content-type',
  18. accept: '*/*',
  19. 'accept-encoding': 'gzip, deflate, br',
  20. 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8,en-US;q=0.7,ru;q=0.6'
  21. }
  22.  
  23. router.use(function timeLog(req, res, next) {
  24. console.log(req.headers.authorization); // of course this is will undefined
  25. })
  26.  
  27. import axios from 'axios'
  28.  
  29. axios.interceptors.request.use((req) => {
  30. req.headers.authorization = `Bearer: ${MYTOKEN}`;
  31. return req;
  32. });
  33.  
  34. router.use(function timeLog(req, res, next) {
  35. console.log(axios.headers.authorization); // here we are
  36. })
Add Comment
Please, Sign In to add comment