Last active
January 17, 2019 11:34
-
-
Save timhudson/5288685 to your computer and use it in GitHub Desktop.
Internal routing within a single node process using express
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
var request = require('request') | |
, express = require('express') | |
, app = express() | |
var port = process.env.PORT || 5000 | |
app.get('/api', function(req, res) { | |
res.send('I am from the API') | |
}) | |
app.get('/internal', function(req, res) { | |
request('http://localhost:'+port+'/api').pipe(res) // Will send 'I am from the API' | |
}) | |
app.listen(port) |
That kind of looks external to me :-p.
Agreed!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That kind of looks external to me :-p.