node. JS Express cross-domain issues

Source: Internet
Author: User

node. JS Express cross-domain problem solved this problem, that's really cool!

Cross-domain problem mainly in the header of the first to provide a world-class header definition http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html and then provide a netizen to provide a detailed header Http://kb.cnblogs.com/page/92320/these two help to understand the type and function of the header, but unfortunately the cross-domain related two header properties I have not found the relevant definition, the following directly tell you 1 is access-control-allow-origin allowed domain 2 is the header type allowed by access-control-allow-headers

The first item can be set directly to * denotes any but the second item cannot be written like this, testing cross-domain discovery error in chrome, the final code looks like this:

function (req, res, next) {    Res.header ("Access-control-allow-origin", "*");    Res.header ("Access-control-allow-headers", "Content-type,content-length, Authorization, Accept, X-requested-with ");    Res.header ("Access-control-allow-methods", "put,post,get,delete,options");    Res.header ("x-powered-by", ' 3.2.1 ')    if(req.method== "Options") res.send (200); /* get the options request back quickly */    Else   Next ();});

 

node. JS Express cross-domain issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.