Express JS: No 'Access-Control-Allow-Origin' header is present on the requested resource

前端 未结 3 727
暗喜
暗喜 2020-12-09 00:02

I have an API running on a server and a front-end client connecting to it to retrieve data. I did some research on the cross domain problem and has it working. However I\'ve

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 00:09

    Check your server.js file. It should look like the example below:

    const express = require('express');
    const bodyParser = require('body-parser');
    var cors = require('cors');
    const mongoose = require('mongoose');
    // create express app
    const app = express();
    
    // parse application/x-www-form-urlencoded
    app.use(bodyParser.urlencoded({ extended: true }))
    
    // parse application/json
    app.use(bodyParser.json())
    
    app.use(cors());
    

提交回复
热议问题