1

I am using Durandal for developing a SPA and so far it is quite amazing. The challenge in hand is - Some of the view and view model resides in a different server (SERVER2) and the app has to reach out to the server and render the content in the SPA which is in SERVER1.

From the analysis done so far the router and viewLocator provides use convention which can take values for different structure, but this always looks at the same application level. For the scenario in hand, the view needs to come from different server - http://server2/anotherapp/app/views/someview.html.

Is this possible to achieve?

Deeps
  • 91
  • 1
  • 6

1 Answers1

1

Yes, this is possible.

Durandal uses RequireJs to resolve and load the views and view models. Once you get the requireJS configuration set up properly, Durandal will load views and view models from different servers without knowing the difference.

Take a look at this answer which describes how to set up RequireJS to resolve certain paths from a second server: RequireJS: Is there a way to achieve multiple base URLs?

The gist of it is that you can configure an element in your path to resolve to a different server. If you only have a couple of modules, you can alias the entire path, but if you have a lot of files, you may need to rethink the organizational structure of your files so that you can group all files from the second server into a common path.

You may be able to configure or tweak Durandal to do what you want, but I think the best solution will be around configuring RequireJS.

Community
  • 1
  • 1
Joseph Gabriel
  • 8,339
  • 3
  • 39
  • 53
  • Thanks for your quick response, part of my issue has been resolved. In the sense when I have the same domain 'localhost' it seems to pick up the js and html files properly from a different virtual directory. But when it comes to different domain - localhost and sampledomain; the js (viewmodel) gets downloaded without any error but instead of getting view.html it rather searches for view.html.js by require.js. Any comments on this behavior? Thanks. – Deeps Apr 16 '13 at 11:11
  • I'm getting same issue where Durandal is appending .js to my html file when attempting to find the file on a different server. Have you solved this problem? – Tom Schreck Mar 17 '14 at 05:28
  • This is "by design" - or at least is known behavior due to browser security restrictions. Basically, it's a result of restrictions on cross-domain ajax requests. See this question/answer for more detail: http://stackoverflow.com/questions/10607370/require-js-text-plugin-adds-js-to-the-file-name?rq=1 – Joseph Gabriel Mar 17 '14 at 15:21
  • Thank you for the link. I found where I have to configure require Text to allow cross domain requests. After applying config, '.js' is no longer appended to URL. However, I'm getting 'allElements is null' error in Durandal's viewEngine.js. The target html file is a simple

    tag to see if content would be pulled in. Any ideas on error message?

    – Tom Schreck Mar 17 '14 at 23:13