You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Configure remoting options via app.set and config.json #608
#433 adds a remoting option normalizeHttpPath. At the moment, the only way how to set this options is to modify server/server.js and change the line calling loopback.rest().
We should modify loopback.rest() to read default options via app.get(). Since app.get() options are already populated from config.json by loopback-boot, this change will allow developers to keep the configuration in json files.
@bajtos@raymondfeng unfortunately, normalizeHttpPath: true from server/config.json doesn't seem to work as expected. The option is never made available to https://github.com/strongloop/loopback/blob/master/lib/model.js#L120 which means the only way to currently do this, is using Model.settings.remoting.normalizeHttpPath = true, which defeats the purpose. It's usually something you'd switch on for your whole app.
@bajtos it is already in the rest section (by default, in a new LB project), yet I don't see how the app-wide setting is used. I tried, but it's never passed to that particular point in the code, and unfortunately I don't see a way to get the app-wide setting there (app is not available in model.js I think).
@fabien Since the option is currently broken, is there a workaround that can force the enabling of normalizeHttpPath? Your suggestion of Model.settings.remoting.normalizeHttpPath = true doesn't seem to quite work.
@mc10 I'm afraid this is the only option right now, we need to look in to the issue. You might be able to iterate over all models in a boot script, and set normalizeHttpPath on each model. For this to work, the bootscript should run before the point where the api is initialized on boot.
I'm not sure how I'd go about iterating through the models individually--would you mind explaining? As a stopgap measure I've used a remoting option in each individual model's JSON file.
@crandmck I will look into documentation requirements once the PR landed. I believe that what I found online is actually vague enough that it is not wrong for the new behavior.
Bu I just realized that while normalizeHttpPath is mentioned in the documentation of config.json for LB 2, it is gone from LB 3's docs:
IIRC, rest. normalizeHttpPath path does not work and the feature should be configured in server/middleware.json instead. I am not entirely sure about this, it would be best to add a unit-test to loopback project to verify which approach actually works: remoting options in config.json or loopback#rest parameters in server/middleware.json or perhaps both.
rest.normalizeHttpPath works for me with the above PR, no need for middleware. I am happy to look into unit tests for the various scenarios. Into which module would they go? strong-remoting also?
I am happy to look into unit tests for the various scenarios. Into which module would they go? strong-remoting also?
That's great to hear! These tests should go to strongloop/loopback, to verify our assumptions about how strong-remoting works inside LoopBack apps. You will need to install your development version of strong-remoting into your loopback project, I personally use npm link.
We already have a test for model-level normalization here, so just add a new test for application-level normalization.
Activity
ritch commentedon Oct 2, 2014
👍
fabien commentedon Jul 8, 2015
@bajtos @raymondfeng unfortunately,
normalizeHttpPath: truefrom server/config.json doesn't seem to work as expected. The option is never made available to https://github.com/strongloop/loopback/blob/master/lib/model.js#L120 which means the only way to currently do this, is usingModel.settings.remoting.normalizeHttpPath = true, which defeats the purpose. It's usually something you'd switch on for your whole app.bajtos commentedon Jul 9, 2015
If I am reading #164 correctly, then you need to set the flag inside
restsection:{ "remoting": { "rest": {"normalizeHttpPath": true} } }I think it's not necessary to pass the option to https://github.com/strongloop/loopback/blob/master/lib/model.js#L120, because the app-wide setting is IMO used as the default value - see your PR strongloop/strong-remoting#90.
fabien commentedon Jul 9, 2015
@bajtos it is already in the
restsection (by default, in a new LB project), yet I don't see how the app-wide setting is used. I tried, but it's never passed to that particular point in the code, and unfortunately I don't see a way to get the app-wide setting there (app is not available inmodel.jsI think).bajtos commentedon Jul 9, 2015
I see, I guess it is a bug then. I am afraid I don't have enough time to investigate this now myself, sorry for that.
I quickly looked at https://github.com/fabien/strong-remoting/blob/7a46b050b8156d1d6ae10e1283f1444da0c52b4d/lib/remote-objects.js#L135-L145, it seems that global options are applied only to classes gathered via
exports, not to classes already registered via_classes. Perhaps that's the root of the problem?kevinji commentedon Jul 15, 2015
@fabien Since the option is currently broken, is there a workaround that can force the enabling of
normalizeHttpPath? Your suggestion ofModel.settings.remoting.normalizeHttpPath = truedoesn't seem to quite work.fabien commentedon Jul 16, 2015
@mc10 it should work, but I guess it depends on where you declare this setting.
Have you tried adding this in your
model.json?fabien commentedon Jul 16, 2015
@bajtos yes, this is the issue indeed I think.
kevinji commentedon Jul 16, 2015
Do I need to add this to each individual model's
.jsonfiles? That seems quite unwieldy, and you can't change the built-in models either.fabien commentedon Jul 16, 2015
@mc10 I'm afraid this is the only option right now, we need to look in to the issue. You might be able to iterate over all models in a boot script, and set
normalizeHttpPathon each model. For this to work, the bootscript should run before the point where the api is initialized on boot.kevinji commentedon Jul 16, 2015
I'm not sure how I'd go about iterating through the models individually--would you mind explaining? As a stopgap measure I've used a
remotingoption in each individual model's JSON file.19 remaining items
crandmck commentedon Jul 24, 2017
@lehni Will the above PR require any changes to docs (once it's merged)?
If so, could you summarize please?
lehni commentedon Jul 27, 2017
@crandmck I will look into documentation requirements once the PR landed. I believe that what I found online is actually vague enough that it is not wrong for the new behavior.
Bu I just realized that while
normalizeHttpPathis mentioned in the documentation ofconfig.jsonfor LB 2, it is gone from LB 3's docs:https://loopback.io/doc/en/lb2/config.json.html
https://loopback.io/doc/en/lb3/config.json.html
Perhaps it's then simply a question of bringing it back?
crandmck commentedon Jul 27, 2017
I'm sure it was removed for a reason, but if this PR resurrects it, then it's easy enough to reinstate it in the v3 docs. Please advise!
bajtos commentedon Jul 28, 2017
IIRC,
rest. normalizeHttpPathpath does not work and the feature should be configured inserver/middleware.jsoninstead. I am not entirely sure about this, it would be best to add a unit-test to loopback project to verify which approach actually works: remoting options inconfig.jsonorloopback#restparameters inserver/middleware.jsonor perhaps both.lehni commentedon Jul 28, 2017
rest.normalizeHttpPathworks for me with the above PR, no need for middleware. I am happy to look into unit tests for the various scenarios. Into which module would they go?strong-remotingalso?bajtos commentedon Jul 28, 2017
That's great to hear! These tests should go to strongloop/loopback, to verify our assumptions about how strong-remoting works inside LoopBack apps. You will need to install your development version of strong-remoting into your loopback project, I personally use
npm link.We already have a test for model-level normalization here, so just add a new test for application-level normalization.
lehni commentedon Jul 28, 2017
I think I need some help to get this particular test running. I thought I tracked it down to:
...or this, if I wanted to run the tests repeatedly while editing them:
To test things, I then changed this line:
...to:
...hoping, it would trigger an error when running the tests again, but it did not.
What am I doing wrong?
lehni commentedon Jul 28, 2017
Ok, my bad... Turns out it's on the mocha side of things:
lehni commentedon Jul 29, 2017
@bajtos I've created a PR for the tests now: #3527
bajtos commentedon Aug 3, 2017
Closing as done by strongloop/strong-remoting#410 and #3527. Thank you @lehni for this valuable contribution! 👏
crandmck commentedon Aug 3, 2017
So, should I put
rest.normalizeHttpPathback into the v3 docs?bajtos commentedon Aug 4, 2017
@crandmck yes please!
crandmck commentedon Aug 4, 2017
Done with loopbackio/loopback.io@657d537.
See https://loopback.io/doc/en/lb3/config.json.html#remoting-properties
lehni commentedon Aug 7, 2017
@bajtos great news, thank you!