Breeze Entity manager relative path

こ雲淡風輕ζ 提交于 2019-12-12 04:59:11

问题


A similar question is HERE but with no solution. I am able to run my project on localhost but once deployed, loading the metadata fails. Looking into chrome developper tools, the request is sent to http://www.domain.org/breeze/metadata instead of http://www.domain.org/projectname/breeze/metadata. On my localhost, the metadata loads as http://localhost:xxxx/breeze/Metadata. My entity manager is declared as new breeze.EntityManager('breeze'). If I change the entitymanager to new breeze.EntityManager('projectname/breeze') all works fine but it does not work on my localhost. How can I declare the entity manager so that the path is relative to the project and works on my localhost and when deployed?


回答1:


It appears that you can assume that the data server and the web server share the same origin. Therefore, you can construct the origin (whatever that is) from the browser's window.location object (inject $location in Angular):

var origin = location.protocol+'//'+location.host+'/'; // 'ex: http://www.foo.com:3000/'
var projectName = location.hostname === 'localhost' ? '' : 'projectName/';
var serviceName = origin + projectName + 'breeze'.
var manager = new breeze.EntityManager(serviceName);

Alternatively, you could delegate the task to the web server which could construct the service name and plunk it in the web page as a JavaScript variable that you pick up during client-side configuration.

I'm sure you can take it from here if you need to make other assumptions.



来源:https://stackoverflow.com/questions/23767387/breeze-entity-manager-relative-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!