Skip to content

Commit

Permalink
Merge branch 'master' into feature/cls-hooked-3
Browse files Browse the repository at this point in the history
  • Loading branch information
josieusa committed Dec 9, 2016
2 parents e597ef9 + 7cef481 commit 9738804
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
- Please ask questions at https://groups.google.com/forum/#!forum/loopbackjs or
https://gitter.im/strongloop/loopback
- Immediate support is available through our subscription plans, see
https://strongloop.com/api-connect-faqs/
-->

### Bug or feature request

<!--
Mark your choice with an "x" (eg. [x], NOT [*]).
-->

- [ ] Bug
- [ ] Feature request

### Description of feature (or steps to reproduce if bug)



### Link to sample repo to reproduce issue (if bug)



### Expected result



### Actual result (if bug)



### Additional information (Node.js version, LoopBack version, etc)


24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Description


#### Related issues

<!--
Please use the following link syntaxes:
- #49 (to reference issues in the current repository)
- strongloop/loopback#49 (to reference issues in another repository)
-->

- None

### Checklist

<!--
Please mark your choice with an "x" (i.e. [x], see
https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments)
-->

- [ ] New tests added or existing tests modified to cover all changes
- [ ] Code conforms with the [style
guide](http://loopback.io/doc/en/contrib/style-guide.html)
43 changes: 43 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
// Node module: loopback-context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';

var contextPerRequest = require('../server/middleware/per-request.js');
// Use `var lbContext = require('loopback-context');` in your app
var lbContext = require('../');
var loopback = require('loopback');

var app = loopback();

// Configure the context middleware
app.middleware('initial', contextPerRequest());

// Store a request property in the context
app.use(function saveHostToContext(req, res, next) {
var currentContext = lbContext.getCurrentContext();
if (currentContext)
currentContext.set('host', req.hostname);
next();
});

app.use(loopback.rest());

var Color = loopback.createModel('color', {name: String});
Color.beforeRemote('**', function(ctx, unused, next) {
// Inside LoopBack code, you can read the property from the context
var currentContext = lbContext.getCurrentContext();
if (currentContext)
console.log('Request to host %s',
currentContext && currentContext.get('host'));
next();
});

app.dataSource('db', {connector: 'memory'});
app.model(Color, {dataSource: 'db'});

app.listen(3000, function() {
console.log('A list of colors is available at http://localhost:3000/colors');
});
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "loopback-context",
"version": "1.0.0",
"version": "3.0.0-alpha.1",
"description": "Current context for LoopBack applications, based on cls-hooked",
"engines": {
"node": ">=4"
},
"keywords": [
"StrongLoop",
"LoopBack",
Expand All @@ -28,7 +31,7 @@
"dirty-chai": "^1.2.2",
"eslint": "^2.13.1",
"eslint-config-loopback": "^4.0.0",
"loopback": "^3.0.0-alpha.1",
"loopback": "^3.0.0",
"mocha": "^2.5.3",
"supertest": "^1.2.0"
}
Expand Down

0 comments on commit 9738804

Please sign in to comment.