W
W
wufapexef2017-10-04 22:17:26
JavaScript
wufapexef, 2017-10-04 22:17:26

Why isn't a custom header set in axios?

I'm trying to put a custom header in axios according to the instructions, but nothing is set

sendData () {
      axios.post('http://localhost:7777', {
        headers: {
          'X-Custom-Header': 'foobar'
        }
      })
        .then((res) => {
          Cookies.set('Answer', res.data.answer)
        })
    }

'X-Custom-Header': 'foobar'it doesn't go into the query. Why? How to put your title? This is on the server
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', 'http://localhost:8080')
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
  res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type")
  next()
})

app.post('/', (req, res) => {
  console.log(req.headers)
  res.send({
    answer: 'Random shit recieved successfully'
  })
})

UPD. the issue was resolved

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
planc, 2017-10-04
@planc

res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Custom-Header")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question