Created
November 23, 2017 16:45
-
-
Save guyguyon/00b6cdd3952ab593594666447bd62f47 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // index.js | |
| const http = require('http'); | |
| const uuid = require('uuid'); | |
| const SomeResource = require('./some_resource'); | |
| const namespace = require('./node-request-context').createNamespace('some-namespace'); | |
| http.createServer(function (req, res) { | |
| namespace.run(() => { | |
| const transactionId = uuid.v1(); | |
| console.log('Setting a new transaction id => ', transactionId); | |
| namespace.set('tid', transactionId); | |
| console.log(namespace.get('tid')); | |
| const sr = new SomeResource(); | |
| sr.get().then((ans) => { | |
| console.log(namespace.get('tid')); | |
| res.end(ans); | |
| }).catch((err) => { | |
| console.log('Error: ', err); | |
| }) | |
| }) | |
| }).listen(8079); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment