Every time I perform front-end and back-end interactions on different machines, I get into the pit. I think that I can’t connect when my machine can test how to connect. It turns out that I forget the cross-domain request every time I make it! ! !
It is hereby recorded to prevent re-entering the pit!
I have not found the relevant definition of the two header attributes related to cross-domain, let me tell you directly below
1 is the domain allowed by Access-Control-Allow-Origin
2 is the header type allowed by Access-Control-Allow-Headers
//Set up cross domain access
app
.
all
(
'*'
,
function
(
req
,
res
,
next
) {
res
.
header
(
"Access-Control-Allow-Origin"
,
"*"
);
res
.
header
(
"Access-Control-Allow-Headers"
,
"Origin, X-Requested-With, Content-Type, Content-Length,
Authorization, Accept,yourHeaderFeild"
);
res
.
header
(
"Access-Control-Allow-Methods"
,
"PUT,POST,GET,DELETE,OPTIONS"
);
res
.
header
(
"X-Powered-By"
,
' 3.2.1'
)
res
.
header
(
"Content-Type"
,
"application/json;charset=utf-8"
);
next
();
});