TurtleWolfe / Food_Liberation_Front

Food Liberation Front using LoopBack & React
The Unlicense
0 stars 0 forks source link

production back to developement #3

Open TurtleWolfe opened 6 years ago

TurtleWolfe commented 6 years ago

Joe Dodd helped me get it from Cloud 9 to Heroku Now when I move back to Cloud 9 my link to the database is broken, I'm trying to replace it with the environmental variable that was set by Heroku on Cloud 9 but use the .env file to load a different mLAB sandbox than Heroku had set, mainly because I assumed it would not allow connections from any other source than the Heroku App that had made it.. and I need to understand NODE.env better, it appears to function at a separate level on cloud 9 but the point should be to minify development to production like a toggle switch on the same repo, I just made this fork https://github.com/TurtleWolf/flf8080 to experiment with first. I've added the .env & .env.default files

NODE_ENV=development

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=baconpancakes
DB_NAME=tree_fort
MONGODB_URI=mongodb://food-liberation-front:92!1WdzRBH*a@ds261678.mlab.com:61678/food-liberation-front

and then trying to reference _MONGODBURI in
/server/datasources.json

  },
  "mLAB": {
    "host": "",
    "port": 33158,
    "url": "${process.env.MONGODB_URI}",
    "database": "heroku_62wvkfd5",
    "password": "unc5vm3ja56957l8qs6dnlhlfe",
    "name": "mLAB",
    "user": "heroku_62wvkfd5",
    "connector": "mongodb"
  }

dynamic datasource ${SOME_STRING}

require('dotenv').config();

but not sure if or where to call dotenv, it just says as early as possible.. my guess is top of main.js so where 'should' I include it in loopback.. main.js or
server.js?
or should I be passing it into the callback of loopback?

'use strict';

var loopback = require('loopback');
var boot = require('loopback-boot');
     //  feels like it should go here, but I'm still misig something..
    //   or should I be passing it into the callback of loopback?
    //require('dotenv').config();
var app = module.exports = loopback();

app.start = function() {
  // start the web server
  return app.listen(function() {
    app.emit('started');
    var baseUrl = app.get('url').replace(/\/$/, '');
    console.log('Web server listening at: %s', baseUrl);
    if (app.get('loopback-component-explorer')) {
      var explorerPath = app.get('loopback-component-explorer').mountPath;
      console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
    }
  });
};

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
  if (err) throw err;

  // start the server if `$ node server.js`
  if (require.main === module)
    app.start();
});

captureenvvariables