Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Commit

Permalink
Add initial code for notesApp example. Fix isFromExt detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladaionescu committed Jun 7, 2016
1 parent 8504a3c commit d755bd4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
14 changes: 14 additions & 0 deletions examples/notesAppJS/README.md
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 67 additions & 0 deletions examples/notesAppJS/notesBackend/backend.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
4 changes: 4 additions & 0 deletions examples/notesAppJS/notesBackend/lever.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "notesBackend",
"jsEntry": "backend.js"
}
13 changes: 13 additions & 0 deletions examples/notesAppJS/notesBackend/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion host/proxyextout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d755bd4

Please sign in to comment.