-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/cls-hooked-3
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters