No 'Access-Control-Allow-Origin' - Node / Apache Port Issue

后端 未结 13 1674
有刺的猬
有刺的猬 2020-11-22 02:27

i\'ve created a small API using Node/Express and trying to pull data using Angularjs but as my html page is running under apache on localhost:8888 and node API is listen on

13条回答
  •  名媛妹妹
    2020-11-22 03:19

    Another way, is simply add the headers to your route:

    router.get('/', function(req, res) {
        res.setHeader('Access-Control-Allow-Origin', '*');
        res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); // If needed
        res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); // If needed
        res.setHeader('Access-Control-Allow-Credentials', true); // If needed
    
        res.send('cors problem fixed:)');
    });
    

提交回复
热议问题