Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

javascript - With a Worklight Adapter can I change the domain and port for a procedure at runtime?

I am writing a worklight application and it will be connecting to a variety of backend services which will be decided by the consumer after installation. I would like to use adapters to connect the client to the backend services - but want to avoid editting and updating the adapter for each connecting user.

Essentially each customer has a running server I want to connect to - however it will be running on a different port and domain for each customer. I want them to be able to pass those to the adapter to allow a common call to be issued to the customer's backend server.

Is there a way that I can alter the domain and port I set in the adapter's xml file programmatically inside the adapter's javascript for each procedure so the user can tell the server where to issue a request to?

If there is no way to do this - would you recommend connecting directly to the backend and avoiding the use of worklight adapters?

Many thanks,

Andy

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As you have correctly guessed - the client (app) sends an adapter procedure request to the Worklight Server, which then executes whichever it has been programmed to do, connects to where it was asked to (as defined in the adapter XML's connectionPolicy element). This cannot be changed during runtime/once deployed.

I don't know what your app is supposed to do, as the scenario is not entirely clear... but you could pre-deploy all required adapters for all the various backends and their set of connection parameters, and on the client-side write some logic to determine which of the adapters to use. There will definitely be adapter duplication here, but it shouldn't create too much overhead on runtime (but yes on maintainability).

And yes, you could also create your own "interface" to allow the end-user to change the connection parameters prior to sending a direct request to the backend (that is, not use Worklight Adapters), but this doesn't sound like something an end-user needs to mock around with.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...