Perfect solution to NODE. JS cross-origin problems, node. js cross-Origin
My company colleagues (front-end) wrote pages over the past few days and said they could not get the desired JSON. Android iOS can get it, however, he is also a newbie and does not know why he only knows the cross-origin issue of js, and then asks me if I don't understand the frontend. I started Baidu,
Some people say that Google Chrome needs to be configured for cross-origin, and then I add -- disable-web-security next to Google Chrome's target.
However, it was found that an error was still reported and the desired data still could not be obtained. There will be no eyebrows when you keep searching.
Today, Baidu inspired me by the PHP cross-domain, So Baidu found node. js cross-origin problem, and finally I am in the app. the js routing settings contain a piece of cross-origin code to perfectly solve the problem:
Var express = require ('express '); var app = express (); // sets the cross-origin access app. all ('*', function (req, res, next) {res. header ("Access-Control-Allow-Origin", "*"); res. header ("Access-Control-Allow-Headers", "X-Requested-With"); 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 () ;}); // app. listen (0, 8088 );
The above is a small part of the NODE. the perfect solution for JS cross-origin problems is to help you. If you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!