Skip to content
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

Remove the proxy-host and proxy-port, introduce proxy-url instead #567

Closed
wants to merge 7 commits into from

Conversation

petrjanda
Copy link
Contributor

Simplified proxy setup, fixes #465.

@petrjanda
Copy link
Contributor Author

One thing I am wondering though is that I was tempted to use it as:

ember server --proxy-url localhost:3000

Which wouldn't work as url.parse will think 'localhost' is a protocol (http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost).

Proxy will still kick off if I skip the protocol but later result in error, while trying to proxy:

TypeError: Cannot read property 'length' of null
    at slashJoin (/Users/petr/experimental/ember/ember-cli/node_modules/proxy-middleware/index.js:83:9)
    at Object.handle (/Users/petr/experimental/ember/ember-cli/node_modules/proxy-middleware/index.js:24:17)
    at next (/Users/petr/experimental/ember/ember-cli/node_modules/express/node_modules/connect/lib/proto.js:193:15)
    at SendStream.<anonymous> (/Users/petr/experimental/ember/ember-cli/node_modules/broccoli/lib/middleware.js:17:13)
    at SendStream.EventEmitter.emit (events.js:95:17)
    at SendStream.error (/Users/petr/experimental/ember/ember-cli/node_modules/broccoli/node_modules/send/lib/send.js:147:51)
    at SendStream.onStatError (/Users/petr/experimental/ember/ember-cli/node_modules/broccoli/node_modules/send/lib/send.js:248:48)
    at /Users/petr/experimental/ember/ember-cli/node_modules/broccoli/node_modules/send/lib/send.js:320:26
    at Object.oncomplete (fs.js:107:15)
ember server --proxy-url http://localhost:3000

is valid usage.

@MajorBreakfast
Copy link
Contributor

Jep you should append http:// automatically if it wasn't specified. The shorter it is the more convenient. Also consider correcting the url to http://localhost:4875 for 4875 (Just a port number)

Sry for closing and reopening this. I've hit the button accidentally.

@@ -10,8 +10,7 @@ module.exports = Command.extend({
availableOptions: [
{ name: 'port', type: Number, default: 4200 },
{ name: 'host', type: String, default: '0.0.0.0' },
{ name: 'proxy-port', type: Number },
{ name: 'proxy-host', type: String },
{ name: 'proxy-url', type: String },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just --proxy ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although --proxy works, too (because nopt expands it), I also think we could just call it --proxy. It's simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sounds good.

@stefanpenner
Copy link
Contributor

i like this approach, can you add some tests, and an entry in the changelog?

@stefanpenner
Copy link
Contributor

@MajorBreakfast im not concerned about length, this will most commonly be driven from the dotfile

@petrjanda
Copy link
Contributor Author

To me url.parse('localhost:3000') resulting in:

{ protocol: 'localhost:',
  slashes: null,
  auth: null,
  host: '3000',
  port: null,
  hostname: '3000',
  hash: null,
  search: null,
  query: null,
  pathname: null,
  path: null,
  href: 'localhost:3000' }

itself does feel wrong. I've asked node.js team about it (nodejs/node-v0.x-archive#7547). Eventually if url.parse would behave more as expected (initializing host/port), it would be easier to plug in defaults after url is parsed, rather then fiddling with defaults on strings level.

@petrjanda
Copy link
Contributor Author

@stefanpenner Yeah couldn't find any proxy related tests so can add some. I am not too familiar with the codebase though. To what level (integration/unit) you want to test it?

@MajorBreakfast
Copy link
Contributor

@stefanpenner I think calling proxy should be fine. I don't think that we'll get another proxy option.
@petrjanda That's not really a bug. url.parse expects a valid url as input. If it doesn't get one its behaviour is kind of undefined. Either way we shouldn't depend on it.

if (/^\d*$/.test(options.proxy)) { proxy = 'http://localhost:' + proxy }
if (!/^https?:\/\//.test(options.proxy)) { proxy = 'http://' + proxy }

@petrjanda
Copy link
Contributor Author

@MajorBreakfast Yeah, that would certainly work.

Alternative approach might be to expect the ember-cliuser to provide the valid url for proxying as well. What feels wrong is to let it go through so he would run into issues I described above.

So yeah, solution injecting defaults or better error feedback both look good to me. If going for defaults, should it be somewhere explicitly mentioned or we expect 'http://localhost:' as implicit "reasonable" default?

@stefanpenner
Copy link
Contributor

@petrjanda status? Would love to get this in for this weekends release.

@petrjanda
Copy link
Contributor Author

@stefanpenner couldn't figure out nice way to test it. Suggestions?

What about the defaults (protocol / domain)? Shall we add them as well?

@stefanpenner
Copy link
Contributor

I would prefer we only allowed the fully qualified uri for now. No short cuts

@stefanpenner
Copy link
Contributor

@petrjanda like a test in: https://github.com/stefanpenner/ember-cli/blob/master/tests/unit/cli/cli-test.js to ensure the param gets passed through.

And another test to ensure the serve task when given the URI passes it through to the server

@@ -125,6 +125,17 @@ describe('Unit: CLI', function() {

describe('server', function() {
['server','s'].forEach(function(command) {
it('expects version in UI output', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this to separate test. I wanted to increase output.length in assert as proxy does write extra line to the output but because of stub the server command is actually never called in this spec so was rather confusing. Afaik only output it handles is before command.validateAndRun is triggered.

it('should start proxy if ```proxy``` URI is given', function() {
expressServer.ui = new MockUI();
return expressServer.start({proxy: 'http://localhost:3000/'}).then(function() {
var output = expressServer.ui.output.trim().split('\n');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really best test. I cant use stub test helper for constructors, right? I think stubbing and testing the call to proxy would be ideal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also match against the output make sure it contains the proxy URI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@stefanpenner
Copy link
Contributor

this is looking pretty good, let me know when its ready. (it will also need a rebase)


assert.equal(serveRun.called, 1, 'expected run to be called once');

assert.equal(options.proxy, 'http://localhost:3000/', 'has correct port');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has correct proxy?

@abuiles abuiles mentioned this pull request May 6, 2014
@stefanpenner
Copy link
Contributor

merged manually f672ede

@rwjblue rwjblue mentioned this pull request May 7, 2014
@ndreckshage
Copy link

this is great. thanks, a lot better than launching chrome without web security

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage of proxy-host
5 participants