= http://localhost:3001/api/;
const payload = { name: "john"}
const header = {
'Content-Type' : 'application/json',
'Authorization' : token,
'Access-Control-Allow-Origins' : '*'
}
const request = async () => {
const postData = await axios.post(url, payload, header)
}
Express:
const express = require ('express');
const cors = require ('cors');
const router = require('express'). Router ();
const app = express ();
app.use(cors);
router.post('/', async (req, res) => {
console.log(' post req ran')
}
The request with cors enabled just remains pending and without cors enabled fails!
Can anyone help out with this?
1. It's Access-Control-Allow-Origin 2. That's a response header, not a request header, so the server must respond with it
3. I'm pretty sure that's NOT how you pass headers to axios
4. The router is never attached to your express app
router.post('/api',....)
5.
At the first time i didn't pass Access-Control-Allow-Origin header but no results
This is a middle ware and router is working as when i don't pass payload and header, the server logs!
Then you didn't show all code
Обсуждают сегодня