如何在 javascript 中设计单页应用程序以在环境模式下工作?
我正在使用 javascript 开发单页应用程序并使用来自 RESTful Web 服务的数据。我将其托管在简单的 lighttpd Web 服务器上。我希望有不同的 url 来按环境消费数据,例如开发模式指向我的本地 Web 服务,生产模式指向在线 Web 服务。
I'm developing single page application in javascript and consume data from RESTful web service. I host it on simple lighttpd web server. I want to have different url for consuming data by environment like development mode points to my local web service and production mode point to online webservice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过包装器路由所有
XMLHttpRequest
。在此包装器中,初始化基本上为所有传出请求设置基本 URL 的环境。由于您使用的是 RESTful 设计,我想每个环境的 URI 都是相同的,只有基本路径会发生变化。Route all
XMLHttpRequest
through a wrapper. In this wrapper, initialize the environment that basically sets the base URL for all outgoing requests. Since you're using a RESTful design, I suppose the URIs are going to be the same for each environment, only the base path is going to change.