-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add remoting options to server/config.json #164
Conversation
server.use(restApiRoot, server.loopback.rest()); | ||
var remotingOptions = server.get('remoting') || {}; | ||
var restOptions = remotingOptions.rest || {}; | ||
server.use(restApiRoot, server.loopback.rest(restOptions)); |
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.
The general approach is to keep the templates as small as possible and implement most features in loopack. That way we can roll bugfixes without having to ask the users to upgrade the generated code.
AFAIK, loopback.rest
has access to the app
object it is mounted on, thus it can read app.get('remoting')
itself, there is no need to pass it down from here.
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.
How to access the app
instance from loopback.rest? I understand the app
instance is available from req.app
.
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.
See lib/middleware/rest.js#L27, it is already accessing the app.
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.
The trick is that you have the application available only at request-handling time, not at the time you are building the middleware/handler function.
{ name: 'port', value: 3000 } | ||
{ name: 'port', value: 3000 }, | ||
{ name: 'remoting', value: { | ||
rest: {context: {enableHttpContext: false}, normalizeHttpPath: false}, |
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.
The comments in strongloop/loopback#608 indicate that normalizeHttpPath
is read from remoting.normalizeHttpPath
, not remoting.rest.normalizeHttpPath
.
Please write an automated test to verify we got this right. Something along the lines:
- Assert that
remoting.context.normalizeHttpPath
is defined asfalse
in the scaffolded app. That way the test fails if we change the default config in the future (e.g. move the key to a different place). - Edit
server/config.json
and setnormalizeHttpPath
totrue
. - Setup anything else needed to verify that http paths are normalized.
- Start the server, verify that http paths are normalized now.
Ideally, there should be one test for each of the config options. To be realistic, I think it should be ok to test only enableHttpContext
and normalizeHttpPath
.
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.
Also the default config is missing enableContext
option as mentioned in strongloop/loopback#337
I feel the proposed config option structure is not optimal.
Assuming the most common usage is to enable context middleware either for all transports (REST, JSON-RPC, WebSocket) or none of them, it makes more sense to have the context options on the top level.
I am not entirely sure where does The goal of this exercise is to approach this problem from the POV of the future user and come up with a solution that will be easiest to understand and use, instead of using the current implementation details to drive the user interface. |
Does |
Yes, AFAIK. I assume JSON-RPC and WebSocket uses method names (e.g. |
See also strongloop/loopback#708. |
169b34d
to
6abf5b1
Compare
@bajtos I updated the remoting options to be: {
context: {enableHttpContext: false},
rest: {normalizeHttpPath: false},
json: {strict: false, limit: '100kb'},
urlencoded: {extended: true, limit: '100kb'},
cors: {origin: true, credentials: true}
} The changes to boot/rest-api.js is also reverted. |
Is it worth adding |
rest: {normalizeHttpPath: false}, | ||
json: {strict: false, limit: '100kb'}, | ||
urlencoded: {extended: true, limit: '100kb'}, | ||
cors: {origin: true, credentials: true} |
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.
Please fix the coding style - add space inside curly brackets.
6abf5b1
to
09494ad
Compare
Fixed the style and added errorHandler. |
enableHttpContext: false | ||
}, | ||
rest: { | ||
normalizeHttpPath: false |
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 want to add xml: false
too?
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.
It would be nice to add I did not verify that the values in template match LoopBack's defaults. LGTM. |
09494ad
to
d0a87c8
Compare
Added rest.xml and rest.supportedTypes. |
Add remoting options to server/config.json
rest: { | ||
normalizeHttpPath: false, | ||
xml: false, | ||
supportedTypes: ['json', 'application/javascript', 'text/javascript'] |
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.
This is not great. It means that to enable xml
, you have to edit both xml
and supportedTypes
now.
Before this PR, it was enough to add xml:true
and developers did not need to worry about content types.
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.
Should I remove supportedTypes: ['json', 'application/javascript', 'text/javascript']
?
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.
Yes, that will be the best.
Here are some alternatives:
- Change the value of
supportedTypes
to list all types including xml types. I find that a bit confusing, plus it is difficult to upgrade. You have to upgrade your config file if you want to use a new JSON-based type likeapplication/vnd.api+json
. - Keep the current value, tell people to delete
supportedTypes
together with changingxml:true
. However, the problem with upgrades is still present.
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.
See b682a70
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.
👍 thanks
/to @bajtos @ritch
See strongloop/loopback#608
See strongloop/loopback#337