Mithril.js: X-CSRF-TOKEN

Created on 24 May 2017  路  5Comments  路  Source: MithrilJS/mithril.js

is there any way to add X-CSRF-TOKEN header globally.
Without add it to every request.

Most helpful comment

sure... just create a new function

const headers = ()=> ({headers: {'X-CSRF-TOKEN': 'whatever'}});
const request = (...args)=>
  args.length > 1 || typeof args[0] === 'string'
    ? m.request(args[0], Object.assign(headers(), args[1] || {}))
    : m.request(Object.assign(headers(), args[0] || {}));

Then just use that in stead of m.request

Alternatively you can monkeypatch m.request with something like the above function.

All 5 comments

sure... just create a new function

const headers = ()=> ({headers: {'X-CSRF-TOKEN': 'whatever'}});
const request = (...args)=>
  args.length > 1 || typeof args[0] === 'string'
    ? m.request(args[0], Object.assign(headers(), args[1] || {}))
    : m.request(Object.assign(headers(), args[0] || {}));

Then just use that in stead of m.request

Alternatively you can monkeypatch m.request with something like the above function.

@nordfjord Thank you :+1:

@isiahmeadows need your help here. is there any way to add a global config on all mithril requests

@naveennagan No, and in general, I would be against it. It's pretty easy to create a wrapper function setting exactly what you need.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephanHoyer picture StephanHoyer  路  4Comments

volnei picture volnei  路  3Comments

raykyri picture raykyri  路  4Comments

barneycarroll picture barneycarroll  路  3Comments

marciomunhoz picture marciomunhoz  路  4Comments