nodejs在面对非简单跨域的时候怎么设置预请求头。求指教!!!

nodejs怎么处理非简单的cors时预请求的头处理。以下是我的代码但是不通过。

node代码:

    var http = require('http');
    var server = http.createServer(function(req, res) {
    res.writeHeader(200,{
        'content-type':'application/json',
        'Access-Control-Allow-Origin' : '*',
        'Access-Control-Request-Method':'POST,GET,OPTIONS',
        'Access-Control-Request-Headers':'content-type'});
    res.on('data',function(d){
        console.log(d);
    })
    var a={
        'name':'test'
    };
    console.log(a);
    res.write(JSON.stringify(a));
    res.end();
    }).listen('8080');

前端代码:

    <script type="text/javascript">
        var xhr=new XMLHttpRequest();
        xhr.onreadystatechange=function(){
            if(xhr.readyState==4){
                if (xhr.status>=200&&xhr.status<300) {
                    var req=xhr.responseText;
                    console.log(req);
                    console.log(xhr.getAllResponseHeaders())
                    document.getElementById('test').innerHTML=req;
                }
            }
        }
        xhr.open('post','http://127.0.0.1:8080/');
        var a={
            'name':'baihaihui'
        }
        var data=String(JSON.stringify(a));
        xhr.setRequestHeader('content-type','application/json');
        xhr.send(data);
    </script>

查看回复