I had this fixed by adding app.use(cors())
on my index page of my server, but now that I have added a mongodb URI from mlab I seem to be having an issue with it.
I am getting this error: XMLHttpRequest cannot load http://localhost:3000/posts. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
Here is my index.js:
require('babel-core/register')({
"presets":["es2015", "react", "stage-1"]
});
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const router = require('./router');
const mongoose = require('mongoose');
const cors = require('cors');
const path = require('path');
var favicon = require('serve-favicon');
//DB setup
mongoose.connect('mongodb://****:****@****:****/*****')
mongoose.Promise = global.Promise;
//App setup
const app = express();
app.use(express.static(__dirname + "../client/public"));
// app.use(morgan('combined'));
router(app);
app.use(cors());
app.use(bodyParser.json({type: '*/*'}))
//Server setup
const port = process.env.PORT || 3000;
app.listen(port, function() {
console.log('Server listening on: ', port);
});