简体   繁体   English

将相同的Javascript Webapp构建部署到不同的环境

[英]Deploy same Javascript webapp build to different environments

I have an ExtJS application and some different environments (local machine, development, production-like test environment, and production). 我有一个ExtJS应用程序和一些不同的环境(本地计算机,开发,类似于生产的测试环境和生产)。 The ExtJS application is backed by a Java backend which is also running on either a local machine, in a development environment, a production-like test environment or a production environment (not the same servers as where the front end application lives though). ExtJS应用程序由Java后端支持,该Java后端也可以在本地计算机上,开发环境,类似于生产的测试环境或生产环境中运行(尽管与前端应用程序所处的服务器不同)。

For the last two environments, I want to build ONE build of the ExtJS app and first deploy it to the test server, then when ready for release deploy the exact same build to the production server. 对于最后两个环境,我想构建一个ExtJS应用程序的内部版本,然后将其部署到测试服务器,然后在准备发布时将完全相同的内部版本部署到生产服务器。

Question: Is it possible to somehow use the environment where the frontend is deployed, to decide which backend the ExtJS should connect to? 问题:是否可以以某种方式使用部署前端的环境来确定ExtJS应该连接到哪个后端? Since the ExtJS front-end is executed on the client's machine, it doesn't know if it should connect to the production backend or the test backend. 由于ExtJS前端是在客户端计算机上执行的,因此它不知道应该连接到生产后端还是测试后端。

What is the best way to solve a problem like this? 解决此类问题的最佳方法是什么? How (in a clean way) is usually a javascript web application built and deployed to several different environments and communicates with their corresponding backend application? 通常如何(以一种干净的方式)构建一个javascript Web应用程序并将其部署到几个不同的环境中,并与其相应的后端应用程序进行通信?

How (in a clean way) is usually a javascript web application built and deployed to several different environments and communicates with their corresponding backend application? 通常如何(以一种干净的方式)构建一个javascript Web应用程序并将其部署到几个不同的环境中,并与其相应的后端应用程序进行通信?

Well, the case is not very usual. 好吧,这种情况不是很平常。 Usually the backend app would be (at least seemingly) on the same server that the frontend app is loaded from. 通常,后端应用程序(至少表面上)应该与前端应用程序从同一服务器上加载。 Therefore, probably the most hassle free way to accomplish your task is to make the frontend server proxy requests from frontend app to corresponding backend server. 因此,可能最轻松的方式来完成任务是将前端服务器代理请求从前端应用程序发送到相应的后端服务器。 This way frontend app will still talk to its origin server which allows you to have just one build for all environments. 这样,前端应用程序仍将与其原始服务器通信,从而使您仅能针对所有环境构建一个版本。

The "official" way would be to use the per-environment sections in the app.json file like this: “正式”的方式是使用app.json文件中的每个环境部分,如下所示:

"production": {
    "backend": "backend.domain.tld",
    // other stuff
},
"testing": {
    "backend": "backend.testing.domain.tld",
    // other stuff
},
"development": {
    "backend": "backend.dev.domain.tld",
    // other stuff
}

The backend value will end up in the build's classic.json (and/or modern.json ) file. backend值将最终出现在构建的classic.json (和/或modern.json )文件中。 Frontend app will see the value as Ext.manifest.backend . 前端应用程序将看到值为Ext.manifest.backend But this way is effectively creating different builds which you wanted to avoid. 但是这种方式有效地创建了您要避免的不同版本。 Therefore, you could just manually create several versions of classic.json / modern.json files for ONE production build like this: 因此,您可以为一个生产版本手动创建几个classic.json / modern.json文件版本,如下所示:

  • classic.json.testing
  • classic.json.staging
  • classic.json.production

and then use rewriting on the frontend server to respond to "/classic.json" requests with whatever json file matches the server purpose. 然后在前端服务器上使用重写功能,以匹配服务器目的的任何json文件响应“ /classic.json”请求。

Yet another way is to the keep the frontend-backend mapping for ALL environments within the frontend app like this: 另一种方法是在这样的前端应用程序中保留所有环境的前端-后端映射:

var ENV_CONF = {
    'frontend.testing.domain.tld': 'backend.testing.domain.tld',
    'frontend.staging.domain.tld': 'backend.staging.domain.tld',
    'domain.tld': 'backend.domain.tld' // production
};

The app would use location.host as the key and talk to the corresponding backend. 该应用程序将使用location.host作为密钥并与相应的后端通信。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为不同环境构建 Electron - Build Electron for different environments 相同的JavaScript代码在两种不同的环境中的行为不同 - Same JavaScript code behaves differently in two different environments 管理不同构建环境(如QA,UAT,Production)的JavaScript配置文件 - Managing JavaScript config files for different build environments (like QA, UAT, Production) google lighthouse 如何计算 javascript 评估时间以及为什么它在不同环境中的相同脚本差异很大 - how google lighthouse calculates javascript evaluation time and why it varies by a huge margin for same scripts on different environments 针对不同环境自动部署JavaScript项目 - Automated deployment of JavaScript project for different environments 设置 vue.config.js 根据环境构建不同的页面 - Set vue.config.js to build different pages depends on environments 为什么JavaScript“ this”在节点和浏览器环境中返回不同的值? - Why does JavaScript “this” returns different values in Node and Browser environments? 有没有办法让 Gulp 在不同的环境中跳过或包含 JavaScript 段? - Is there a way to make Gulp skip or include JavaScript segments in different environments? 用于在不同环境中测试的javascript中的selenium-webdriver的策略 - Strategy for selenium-webdriver in javascript for testing in different environments 如何自动部署简单的 Vue WebApp(不需要服务器)? (即使用 vue 的简单构建链) - How to automate deploy of simple Vue WebApp (no server required)? (i.e. simple build chain with vue)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM