Permalink
Browse files

Add initial code for notesApp example. Fix isFromExt detection.

  • Loading branch information...
vlad-alexandru-ionescu committed Jun 7, 2016
1 parent 8504a3c commit d755bd4f8bc0fe4dc910d799cbeaf30d80ad4833
@@ -0,0 +1,14 @@
+A Notes app
+===========
+
+To run this example
+
+```bash
+$ docker run -p 172.17.0.1:27017:27017 --name notes-mongo -d mongo
+
+$ cd notesBackend
+$ npm install
+$ lever deploy
+```
+
+... To be continued.
@@ -0,0 +1,67 @@
+
+'use strict';
+
+const MongoClient = require('mongodb').MongoClient;
+const lodash = require('lodash');
+
+const mongoUrl = 'mongodb://172.17.0.1:27017/notesApp'
+
+module.exports.addNote = (note, callback) => {
+ getDb((err, db) => {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ db.collection('notes').insertOne({
+ note,
+ }, (err, result) => {
+ if (err) {
+ console.log(err);
+ callback(err);
+ return;
+ }
+
+ callback(null, null);
+ });
+ });
+};
+
+module.exports.getNotes = (callback) => {
+ getDb((err, db) => {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ db.collection('notes').find({}).toArray((err, docs) => {
+ if (err) {
+ console.log(err);
+ callback(err);
+ return;
+ }
+
+ const notes = lodash.map(docs, (doc) => {
+ return doc.note;
+ });
+ callback(null, notes);
+ });
+ });
+};
+
+let cachedDb = null;
+function getDb(callback) {
+ if (cachedDb !== null) {
+ callback(null, cachedDb);
+ return;
+ }
+ MongoClient.connect(mongoUrl, (err, db) => {
+ if (err) {
+ console.log(err);
+ callback(err);
+ return;
+ }
+ cachedDb = db;
+ callback(null, db);
+ });
+}
@@ -0,0 +1,4 @@
+{
+ "name": "notesBackend",
+ "jsEntry": "backend.js"
+}
@@ -0,0 +1,13 @@
+{
+ "name": "notes-backend",
+ "version": "0.0.0",
+ "description": "",
+ "main": "backend.js",
+ "author": "",
+ "license": "Apache-2.0",
+ "private": true,
+ "dependencies": {
+ "lodash": "^4.13.1",
+ "mongodb": "^2.1.21"
+ }
+}
View
@@ -102,7 +102,7 @@ func (proxy *LeverProxy) handleExtOutStream(
).Debug("Receiving stream")
streamLogger = streamLogger.WithFields("streamID", streamID)
- isFromExt := core.IsInternalEnvironment(srcEnv)
+ isFromExt := !core.IsInternalEnvironment(srcEnv)
hostInfo, err := proxy.finder.GetHost(
leverURL.Environment, leverURL.Service, leverURL.Resource, isFromExt)
if err != nil {

0 comments on commit d755bd4

Please sign in to comment.