So I have a Ubuntu server running Apache, Node & Mongo. I can return data from my database via CURL on the server. The node backend is definitely running on port 3000.My React frontend uses Fetch and I currently have it pointed at localhost:3000. Is this wrong?I'm also a little confused as to where my frontend React bundle should be on my server in relation to my server.js. Does that matter?I can access the frontend through my domain, it just isn't grabbing the data the way it did when I worked on it locally. I must be missing something in my server.js to get them to talk to each other...I read about Apache VirtualHost and how that might be a necessary component in running a node app on a single Apache server.Here's the httpservice.js file from the frontend:var Fetch = require('whatwg-fetch'); var baseUrl = 'http://localhost:3000'; var service = { get: function(url) { return fetch(baseUrl + url) .then(function(response) { return response.json(); }); }, post: function(url, ingredient) { return fetch(baseUrl + url, { headers: { 'Accept': 'text/plain', 'Content-Type': 'application/json' }, method: 'post', body: JSON.stringify(ingredient) }).then(function(response) { return response; }); } }; module.exports = service; And here's my server.js from the backend:var express = require('express'); var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bodyParser = require('body-parser'); var app = express(); mongoose.connect('mongodb://admin:admin123@127.0.0.1:27017/food?authSource=admin'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: false})); var usersSchema = new Schema({ id: String, vote: Number }); var bkyes = mongoose.model('bkyes', usersSchema); app.get('/bkyes', function(req, res) { bkyes.find({}, function(err, bkyes) { res.send(bkyes); }); }); app.listen(3000); Thanks so much for any insights, all are welcome and appreciated!!!
Submitted December 02, 2016 at 11:07AM by joWebDev
No comments:
Post a Comment