-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Explicit proxies #1530
Merged
Merged
[WIP] Explicit proxies #1530
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1488e7d
Add http-proxy generator/blueprint
trek 81dfc7c
setup proxies with http-proxy
EndangeredMassa 670b177
Add http-proxy as a dependecy in case someone uses proxies
trek 00fcbab
Makes routing go addon middlewares, mocks, proxies, app.
trek b89f0a5
Make proxies with with requests that have bodies.
trek c368844
Add connect-restreamer as a dependency
trek a39ca9f
Integration tests for proxies
trek caaf928
Merge branch 'master' into explicit-proxies
trek 2777c84
Add info about proxies and mocks to CHANGELOG
trek 4a436cb
Merge remote-tracking branch 'upstream/master' into explicit-proxies
EndangeredMassa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,29 @@ | ||
// To use it create some files under `routes/` | ||
// e.g. `server/routes/ember-hamsters.js` | ||
// | ||
// module.exports = function(app) { | ||
// app.get('/ember-hamsters', function(req, res) { | ||
// res.send('hello'); | ||
// }); | ||
// }; | ||
|
||
var bodyParser = require('body-parser'); | ||
var globSync = require('glob').sync; | ||
var mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require); | ||
var proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require); | ||
|
||
module.exports = function(app) { | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ | ||
extended: true | ||
})); | ||
|
||
mocks.forEach(function(route) { route(app)}); | ||
|
||
// proxy expects a stream, but express will have turned | ||
// the request stream into an object because bodyParser | ||
// has run. We have to convert it back to stream: | ||
// https://github.com/nodejitsu/node-http-proxy/issues/180 | ||
app.use(require('connect-restreamer')()); | ||
proxies.forEach(function(route) { route(app)}); | ||
}; |
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
{ | ||
"node": true | ||
} |
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,29 @@ | ||
// To use it create some files under `routes/` | ||
// e.g. `server/routes/ember-hamsters.js` | ||
// | ||
// module.exports = function(app) { | ||
// app.get('/ember-hamsters', function(req, res) { | ||
// res.send('hello'); | ||
// }); | ||
// }; | ||
|
||
var bodyParser = require('body-parser'); | ||
var globSync = require('glob').sync; | ||
var mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require); | ||
var proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require); | ||
|
||
module.exports = function(app) { | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ | ||
extended: true | ||
})); | ||
|
||
mocks.forEach(function(route) { route(app)}); | ||
|
||
// proxy expects a stream, but express will have turned | ||
// the request stream into an object because bodyParser | ||
// has run. We have to convert it back to stream: | ||
// https://github.com/nodejitsu/node-http-proxy/issues/180 | ||
app.use(require('connect-restreamer')()); | ||
proxies.forEach(function(route) { route(app)}); | ||
}; |
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,14 @@ | ||
var Proxy = require('http-proxy'); | ||
|
||
// For options, see: | ||
// https://github.com/nodejitsu/node-http-proxy | ||
var proxy = Proxy.createProxyServer({}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
module.exports = function(app) { | ||
|
||
app.use('/<%=camelizedModuleName %>', function(req, res, next){ | ||
proxy.web(req, res, { target: '<%=proxyUrl %>' }); | ||
}) | ||
|
||
}; | ||
|
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,11 @@ | ||
var Blueprint = require('../../lib/models/blueprint'); | ||
|
||
module.exports = Blueprint.extend({ | ||
locals: function(options) { | ||
var proxyUrl = options.args[2]; | ||
return { | ||
path: '/' + options.entity.name.replace(/^\//, ''), | ||
proxyUrl: proxyUrl | ||
}; | ||
} | ||
}); |
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
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the bodyParser was giving proxy users trouble
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you remember what kind of troubles? We were able to successfully proxy, but we're also using json. Was it proxying to non-json that was problematic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm found it #925
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using body parser caused post and put requests to fail, IIRC.