Breeze Entity经理的相对路径 [英] Breeze Entity manager relative path

查看:156
本文介绍了Breeze Entity经理的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似的问题是这里,但没有解决方案。我能够在localhost上运行我的项目但是一旦部署,加载元数据就失败了。查看chrome开发工具,请求发送到 http://www.domain.org/breeze/metadata 而不是 http:// www .domain.org /项目名称/微风/元数据。在我的localhost上,元数据加载为 http:// localhost:xxxx / breeze / Metadata 。我的实体管理器被声明为 new breeze.EntityManager('breeze')。如果我将entitymanager更改为 new breeze.EntityManager('projectname / breeze')一切正常,但它在我的localhost上不起作用。如何声明实体管理器以使路径相对于项目并在我的localhost上工作并在部署时?

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?

推荐答案

您似乎可以假设数据服务器和Web服务器共享相同的源。因此,您可以从浏览器的 window.location 对象(注入 $ location )构建原点(无论是什么) Angular):

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);

或者,您可以将任务委派给Web服务器,该服务器可以构造服务名称并将其插入网页作为您在客户端配置期间选择的JavaScript变量。

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.

这篇关于Breeze Entity经理的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆