2017-08-30 77 views
0

當我連接前端時,我很厭煩解決我的錯誤React App與我的Heroku服務器應用程序,當我從我的前端發出請求,正在此問題:將Heroku服務器與我的React App連接時出錯

無法加載https://hidden-reaches-90171.herokuapp.com/GETDATA:沒有 「訪問控制允許來源」標頭出現在請求 資源。原因'http://localhost:3000'因此不允許 訪問。

任何人都可以面對這個問題溶膠請指導我什麼,我做錯了, 感謝

+0

是你的應用程序託管在Heroku上嗎? – SabirAmeen

+0

是的,我的應用程序託管在Heroku上 –

回答

0

試着在你的NodeJS主服務器文件下面的代碼。

app.all('/*', function(request, response, next) { 
    response.header("Access-Control-Allow-Origin", "*"); 
    response.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS'); 
    response.header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept'); 
    if (request.method == 'OPTIONS') { 
    response.status(200).end(); 
    } else { 
    next(); 
    } 
});