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

后端 未结 13 2027
有刺的猬
有刺的猬 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:16

    Hi this happens when the front end and backend is running on different ports. The browser blocks the responses from the backend due to the absence on CORS headers. The solution is to make add the CORS headers in the backend request. The easiest way is to use cors npm package.

    var express = require('express')
    var cors = require('cors')
    var app = express()
    app.use(cors())
    

    This will enable CORS headers in all your request. For more information you can refer to cors documentation

    https://www.npmjs.com/package/cors

提交回复
热议问题