Похожие чаты

React app on port: 3000 Express app on port: 3001 React: const url

= 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?

8 ответов

13 просмотров

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.

Y- Автор вопроса
Thomas
1. It's Access-Control-Allow-Origin 2. That's a re...

At the first time i didn't pass Access-Control-Allow-Origin header but no results

Y- Автор вопроса
Thomas
5.

This is a middle ware and router is working as when i don't pass payload and header, the server logs!

Похожие вопросы

Обсуждают сегодня

Quick reminder regarding the first phase of the token merger⚠️ As we approach Phase 1 of the token merger, OCEAN and AGIX will migrate to FET starting July 1st! Here's a li...
Stip11
1
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
75
Hey, Oceaners 🌊 As we approach Phase 1 of the token merger, OCEAN and AGIX will migrate to FET starting July 1st! Here's a list of exchanges that have communicated their su...
KreigDK | Never DM first🌊
3
VIP 332 Quarterly XVS Buyback, Funds Allocation and New Tokenomics Summary This VIP outlines the protocol’s Quarterly Buyback and Funds Allocation strategy as per our Tokeno...
Venus Announcements
2
База данных не поможет. Шифрование не поможет. Какие там ещё варианты? Накидывайте.
КТ315
20
А табстоп это сообщение от окна или от элемента управления?
The Bird of Hermes
18
Did you guys see the latest tweet from TonGifts? 🚀
Mike
44
I love the passion, really do. I do think this is being blown way out of proportion. We are not deleting our Telegram or not allowing you to talk about anything you want, a...
Mike Herron
3
А как лучше конвертировать физический адрес в виртуальный при маппинге? В случае ядра у меня, например, direct mapping, первые 768МБ я как есть мапплю в higher half, а остальн...
Evg Resh
26
Hey, what is the best and maintained way of transpiling cpp to c? (As a need to support many different toolchains quickly and may not have a c++ support in the given toolch...
Meitar Reihan
11
Карта сайта