Proxy environment switching method and device, equipment and storage medium
By introducing a Vite architecture-based environment switching plug-in during project development, using middleware functions and proxy services to achieve forwarding of target requests, the problem of time-consuming switching of proxy environments is solved and development efficiency is improved.
Patent Information
- Application Number
- CN202510342495.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-07-08
AI Technical Summary
During project development, in the scenario where multiple environments are developed in parallel, the existing technology needs to manually modify the configuration files and restart the service, which makes the proxy environment switch take time and affects development efficiency.
An environment switching plug-in based on Vite architecture is introduced, and the target requests are parsed and extracted through middleware functions, and the requests are forwarded to the target environment using proxy services to avoid configuration file modification and restarting services.
Improve development efficiency, and environment switching can be achieved by adding or modifying the target address in the target type request without changing the configuration file or restarting the project and server.
Smart Images

Figure CN120276820A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of interface agents, and particularly to a method, device, equipment and storage medium for switching proxy environments. Background Art
[0002] During the project development process, the scenario of multiple environments developing in parallel is very common. Each environment corresponds to a different backend service address, so it is necessary to configure different service addresses in the front-end project to achieve proxy switching between different environments. Currently, it is usually achieved by directly modifying the relevant fields of the configuration file and automatically restarting the service to switch the proxy environment; however, after restarting, the file needs to be recompiled, resulting in a long time for switching the proxy environment and greatly affecting the development efficiency. Summary of the Invention
[0003] In view of this, the present invention provides a method, device, equipment and storage medium for switching proxy environments.
[0004] In a first aspect, the present invention provides a method for switching proxy environments, the method comprising:
[0005] Introduce an environment switching plugin into the configuration file of the current development service, and configure and start the environment switching plugin; the environment switching plugin is built based on the vite architecture;
[0006] In response to a target request entering the current development service, call the middleware function in the environment switching plugin to parse and extract parameters from the target request to obtain a target address; the request type of the target request is a target type, and the target type is a request type that triggers the environment switching plugin to perform environment switching;
[0007] Call the proxy service in the environment switching plugin, and forward the target request to the target environment based on the target address, so as to switch the proxy environment to the target environment.
[0008] The method for switching proxy environments provided by the embodiments of the present invention introduces an environment switching plugin for the current development service, calls the middleware function in the environment switching plugin to parse the target request entering the current development service to determine the target address, calls the proxy service in the environment switching plugin, and forwards the target request to the target environment corresponding to the target address, so that it is only necessary to add or modify the target address in the request of the target type to directly switch the proxy environment to the target environment required, without changing the configuration file, restarting the project and the server, thereby improving the development efficiency.
[0009] In an optional implementation manner, configuring and starting the environment switching plugin includes:
[0010] In response to the update of the configuration information of the environment switching plugin, read the configuration information of the environment switching plugin from the configuration file to configure the environment switching plugin;
[0011] Create a middleware function through a hook function and add the middleware function to the current development service;
[0012] Create a proxy service through a service creation method.
[0013] In an optional implementation manner, creating a middleware function through a hook function includes:
[0014] Register a hook function and generate a server instance of the current development service;
[0015] In the hook function, call the middleware addition method of the server instance to create a middleware function;
[0016] Add the middleware function to the server instance.
[0017] In an optional implementation manner, parsing and extracting parameters of a target request to obtain a target address includes:
[0018] Parse the target request based on a preset regular expression to extract target parameters in the target request; the preset regular expression is used to locate parameters at a target position in the target request;
[0019] Determine the target address based on the target parameters.
[0020] In an optional implementation manner, determining the target address based on the target parameters includes:
[0021] If the target parameters contain a uniform resource locator, use the contained uniform resource locator as the target address;
[0022] If the target parameters do not contain a uniform resource locator, obtain a preset address from the configuration information of the environment switching plugin and use the preset address as the target address.
[0023] In an optional implementation manner, forwarding the target request to a target environment based on the target address includes:
[0024] If the target request is encrypted, perform encryption verification on the target request based on the configuration information of the environment switching plugin;
[0025] Forward the target request to the target address to forward the target request to the target environment.
[0026] In an optional implementation manner, an error event listener for listening to the proxy service is also set in the environment switching plugin; this method further includes:
[0027] Through the error event listener, listen to the process of forwarding the target request to the target address;
[0028] If an error event is detected, return the error information corresponding to the error event.
[0029] In a second aspect, the present invention provides a proxy environment switching device, which includes:
[0030] A plugin startup module, which is used to introduce an environment switching plugin into the configuration file of the current development service, and configure and start the environment switching plugin; the environment switching plugin is built based on the vite architecture;
[0031] An address extraction module, which is used to respond to a target request entering the current development service, call the middleware function in the environment switching plugin, parse and extract the parameters of the target request, and obtain the target address; the request type of the target request is the target type, and the target type is the request type that triggers the environment switching plugin to perform environment switching;
[0032] An environment switching module, which is used to call the proxy service in the environment switching plugin, and forward the target request to the target environment based on the target address, so as to switch the proxy environment to the target environment.
[0033] In a third aspect, the present invention provides a computer device, including: a memory and a processor, which are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to execute the proxy environment switching method in the first aspect or any corresponding embodiment thereof.
[0034] In a fourth aspect, the present invention provides a computer-readable storage medium, on which computer instructions are stored, and the computer instructions are used to cause a computer to execute the proxy environment switching method in the first aspect or any corresponding embodiment thereof.
[0035] In a fifth aspect, the present invention provides a computer program product, including computer instructions, and the computer instructions are used to cause a computer to execute the proxy environment switching method in the first aspect or any corresponding embodiment thereof. Description of the Drawings
[0036] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required to be used in the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0037] Figure 1 It is a flowchart of a proxy environment switching method according to an embodiment of the present invention;
[0038] Figure 2 It is a flowchart of another proxy environment switching method according to an embodiment of the present invention;
[0039] Figure 3 It is a flowchart of yet another proxy environment switching method according to an embodiment of the present invention;
[0040] Figure 4 It is a structural block diagram of a proxy environment switching device according to an embodiment of the present invention;
[0041] Figure 5 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Specific embodiments
[0042] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0043] During the project development process, the scenario of cross-parallel development in multiple environments is very common. Each environment corresponds to a different backend service address, which requires configuring different service addresses in the front-end project to achieve proxy switching between different environments. Currently, the method of directly modifying the relevant fields of the configuration file and automatically restarting the service is usually adopted to achieve the proxy switching of the environment; on the one hand, this method requires manual modification of the configuration file, and on the other hand, the file needs to be recompiled after restarting, resulting in a long time-consuming proxy environment switching and greatly affecting the development efficiency.
[0044] Based on this, the present invention provides a proxy environment switching method, which includes: introducing an environment switching plugin into the configuration file of the current development service, and configuring and starting the environment switching plugin; the environment switching plugin is built based on the vite architecture; in response to a target request entering the current development service, calling a middleware function in the environment switching plugin to parse and extract parameters from the target request to obtain a target address; the request type of the target request is a target type, and the target type is a request type that triggers the environment switching plugin to perform environment switching; calling a proxy service in the environment switching plugin, and forwarding the target request to the target environment based on the target address to switch the proxy environment to the target environment. In this way, only by adding or modifying the target address in the request of the target type, the proxy environment can be directly switched to the target environment required, without changing the configuration file, restarting the project and the server, thereby improving the development efficiency.
[0045] The proxy environment switching method provided by the embodiment of the present invention is implemented based on the Vite front-end build tool. The Vite front-end build tool adopts a plug-in architecture design, and the function of the Vite front-end build tool can be extended by customizing plugins without modifying its core code.
[0046] The proxy environment switching method provided by the embodiment of the present invention can be applied to a local development environment equipped with a Vite development environment and related dependencies. An environment switching plugin corresponding to the proxy environment switching method provided by the embodiment of the present invention is configured in Vite to implement dynamic proxy. The local development environment can involve multiple backend proxy environments, such as a local environment (LOCAL), a development environment (DEV), a test environment (QA), and an acceptance environment (UAT); among them, the local environment (LOCAL) is an environment for providing self-MOCK data to front-end developers; the development environment (DEV) is an environment for providing joint debugging during the development process to front-end and back-end personnel; the test environment (QA) is a stable test environment provided to testers after requirements are tested; the acceptance environment (UAT) is used to provide a test acceptance environment for users.
[0047] According to an embodiment of the present invention, on the one hand, an embodiment of a proxy environment switching method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0048] In this embodiment, a proxy environment switching method is provided, which can be applied to the local development environment involving multiple backend proxy environments as described above. Figure 1 is a flowchart of the proxy environment switching method according to an embodiment of the present invention, as Figure 1As shown in the figure, the process includes the following steps:
[0049] Step S101: Introduce an environment switching plugin into the configuration file of the current development service, and configure and start the environment switching plugin.
[0050] In the embodiment of the present invention, the environment switching plugin is built based on the vite architecture. The environment switching plugin is used to intercept a request of a specified type when it enters the current development service, so as to switch the backend proxy environment according to the information contained in the request. Therefore, when a user develops a local project, the user can add or modify the relevant information of the backend proxy environment corresponding to the requirements in a request of a specified type to instruct the environment switching plugin to switch the backend proxy environment, without modifying the configuration file, restarting the project and the server, thereby improving the development efficiency.
[0051] In the embodiment of the present invention, the environment switching plugin is introduced into the configuration file of the current development service, that is, the vite.config.ts configuration file, so as to introduce the environment switching plugin into the current development service. At the same time, the environment switching plugin is configured and started so that the environment switching plugin can be used normally.
[0052] Step S102: In response to a target request entering the current development service, call the middleware function in the environment switching plugin to parse and extract the parameters of the target request to obtain a target address.
[0053] In the embodiment of the present invention, the request type of the target request is a target type, and the target type is the request type that triggers the environment switching plugin to perform environment switching, that is, the specified type described in step S101. When the target request enters the current development service, it will trigger the response of the environment switching plugin. The middleware function in the environment switching plugin will intercept it and parse and extract its parameters to obtain the target address contained therein. The target address is the relevant information indicating the backend proxy environment of the user's needs, and the target address usually can include the domain name and port number of its corresponding backend proxy service.
[0054] In an optional implementation manner, according to the differences in the system or terminal used by the current development service, the input and entry methods of the target request into the current development service are also different, and can be specifically adjusted according to the development environment and the operating system used. For example, for operating systems with a visual interface such as windows, other visual pages such as a browser can be used to input the target request; for operating systems without a visual interface such as linux, the cmd command prompt can be used to input the target request.
[0055] Step S103: Invoke the proxy service in the environment switching plugin and forward the target request to the target environment based on the target address, so as to switch the proxy environment to the target environment.
[0056] In the embodiment of the present invention, after the target address is determined, the proxy service in the environment switching plugin is invoked to implement the forwarding of the request, and the target request is forwarded to the target environment corresponding to the target address, so as to switch the backend proxy environment of the current development service to the target environment.
[0057] In the embodiment of the present invention, the target environment is the backend proxy environment, and different backend proxy environments correspond to different backend services; the backend proxy environment is deployed on a remote server and is used to deploy and test the front-end application.
[0058] In an optional implementation manner, the proxy service calls the proxy.web method to forward the target request to the corresponding target environment. Among them, the proxy.web method receives the relevant parameters for request forwarding, that is, the current request and the target address, and then forwards the current request to the target scenario according to the target address.
[0059] In the embodiment of the present invention, the target request contains the local development address corresponding to the current development service, and the local development address is mainly used to identify and access the service running in the local development environment. During the development process, the front-end and back-end services usually run on different addresses and ports; at this time, the local development address can ensure that the front-end application correctly interacts with the corresponding back-end service. Therefore, including the local development address and the target address of the target environment in the target request can ensure that the current development service can correctly interact with the back-end service corresponding to the target environment, and at the same time, by only modifying the target address of the target environment, the switching of the backend proxy environment can be realized.
[0060] In an alternative embodiment, when forwarding a target request, the forwarding operation of the target request is different according to whether the target request is encrypted. Specifically, if the target request is not encrypted, the target request is directly forwarded to the target address to forward the target request to the target environment; if the target request is encrypted, based on the configuration information of the environment switching plugin, an encryption verification is performed on the target request. After the encryption verification passes, the target request is forwarded to the target address to forward the target request to the target environment. Specifically, for a target request that is an HTTP request, since HTTP is an unencrypted protocol that does not involve any encryption and authentication mechanisms and transmits all data in plain text, the proxy service can be directly called to forward the target request to the target environment. For an HTTPS request, since HTTPS adds an SSL / TLS encryption layer on top of HTTP, uses the SSL / TLS protocol to encrypt data, and performs server authentication through an SSL / TLS certificate to ensure the security of data during transmission, for an HTTPS request, it is necessary to first verify and decrypt the target request based on the verification information in the configuration information of the environment switching plugin. After the verification passes, the target request is forwarded to the target environment.
[0061] In an alternative embodiment, to ensure the stability of the proxy service and thus the stability of the back-end proxy environment switching, an error event listener for monitoring the proxy service is also set in the environment switching plugin. The error event listener can monitor the process of forwarding the target request to the target address. Specifically, through the error event listener, the process of forwarding the target request to the target address is monitored; if an error event is detected, the error information corresponding to the error event is returned to facilitate the user to quickly locate the problem based on the error information.
[0062] The proxy environment switching method provided by the embodiments of the present invention introduces an environment switching plugin for the current development service, calls the middleware function in the environment switching plugin to parse the target request entering the current development service to determine the target address, and calls the proxy service in the environment switching plugin to forward the target request to the target environment corresponding to the target address. Thus, only by adding or modifying the target address in the target type of request, the proxy environment can be directly switched to the required target environment without changing the configuration file, restarting the project, and the server, thereby improving the development efficiency.
[0063] In this embodiment, a proxy environment switching method is provided, which can be applied to the local development environment involving multiple back-end proxy environments as described above. Figure 2 is a flowchart of another proxy environment switching method according to the embodiments of the present invention, as Figure 2 shown, and this process includes the following steps:
[0064] Step S201, introduce an environment switching plugin into the configuration file of the current development service, and configure and start the environment switching plugin.
[0065] Specifically, step S201 includes:
[0066] Step S2011, in response to the update of the configuration information of the environment switching plugin, read the configuration information of the environment switching plugin from the configuration file to configure the environment switching plugin.
[0067] In the embodiment of the present invention, the user can configure, modify or update the configuration information of the environment switching plugin in the vite.config.ts configuration file; wherein, the configuration information of the environment switching plugin includes the default address of the environment switching plugin and other configuration items, etc. In response to the update of the configuration information of the environment switching plugin, read the configuration information of the environment switching plugin from the vite.config.ts configuration file, so as to initialize the proxy configuration of the environment switching plugin and complete the configuration of the environment switching plugin.
[0068] In an alternative embodiment, if the user updates the configuration information of the environment switching plugin, the configuration information of the environment switching plugin will be read again from the vite.config.ts configuration file to configure the environment switching plugin, and the environment switching plugin will be restarted to ensure the correct configuration of the environment switching plugin during use.
[0069] Step S2012, create a middleware function through a hook function and add the middleware function to the current development service.
[0070] In the embodiment of the present invention, a middleware function is created through a hook function and added to the current development service to intervene when the current development service starts.
[0071] Specifically, first, register the hook function and generate a server instance of the current development service. Among them, register the configureServer hook function to customize the configuration of the development server before the development server starts; for example, the configureServer hook function can be used to insert a custom middleware in the development server to handle requests. Extract the configuration related to the current development service from the vite.config.ts configuration file to initialize the configuration of the development server, and then Vite starts an http server using the http module to obtain a server instance serving the current development environment, thus completing the generation of the server instance of the current development service.
[0072] Then, in the hook function, call the middleware addition method of the server instance to create a middleware function.
[0073] Finally, add the middleware function to the server instance. Among them, the method of adding middleware is to call the use method of the.middlewares property of the development server, and call this method in the configureServer hook function to implement the creation and addition of the middleware function.
[0074] Step S2013, create a proxy service through the service creation method.
[0075] In the embodiment of the present invention, the proxy service is used to forward the current request to the corresponding target environment. The proxy service is created based on the service creation method of the http-proxy library, that is, the createProxyServer method. The http-proxy library is used to implement the proxy of HTTP requests and forward the requests from the client to the target server. In this embodiment, that is, to forward the target request from the current development service to the backend proxy service corresponding to the target environment.
[0076] Step S202, in response to the target request entering the current development service, call the middleware function in the environment switching plugin to parse and extract the parameters of the target request to obtain the target address. For details, please refer to Figure 1 Step S102 of the embodiment shown, which will not be elaborated here.
[0077] Step S203, call the proxy service in the environment switching plugin, and based on the target address, forward the target request to the target environment to switch the proxy environment to the target environment. For details, please refer to Figure 1 Step S103 of the embodiment shown, which will not be elaborated here.
[0078] In this embodiment, a proxy environment switching method is provided, which can be applied to the local development environment involving multiple backend proxy environments as described above. Figure 3 It is a flowchart of another proxy environment switching method according to the embodiment of the present invention. As Figure 3 shown, this process includes the following steps:
[0079] Step S301, introduce the environment switching plugin in the configuration file of the current development service, and configure and start the environment switching plugin. For details, please refer to Figure 1 Step S101 of the embodiment shown, which will not be elaborated here.
[0080] Step S302, in response to the target request entering the current development service, call the middleware function in the environment switching plugin to parse and extract the parameters of the target request to obtain the target address.
[0081] Specifically, step S302 includes:
[0082] Step S3021: Parse the target request based on a preset regular expression to extract the target parameter in the target request.
[0083] In the embodiment of the present invention, the preset regular expression is used to locate the parameter at the target position in the target request, and the target parameter is the parameter indicating the switching of the backend proxy environment; usually, the target parameter can be placed at the end of the target request. Correspondingly, the target position is the end of the target request.
[0084] In an optional implementation manner, the structure of the target parameter is "?debug=URL", where URL represents the domain name and port number of the target environment.
[0085] In an optional embodiment, the preset regular expression is specifically: new RegExp('(^|&)debug=([^&]*)(&|$)','i'). Here, RegExp is a built-in constructor for creating a regular expression object; "^" indicates the start of the matching string, that is, starting from the string, which is the beginning of the target request; "|" is a logical OR operator for matching any one of the patterns on its two sides; "('(^|&)" means matching starting from the beginning of the current request or starting after the "&" symbol; "debug=" means matching the character "debug=", that is, looking for the "debug=" parameter in the target request, which is the target parameter; "[^&]" means matching any character that is not "&", and * means that the previous matching pattern appears zero or more times; correspondingly, "[^&]*" is a capture group, indicating matching any character other than "&" after "debug=" until the next "&" or the end of the target request string; "(&|$)" means matching the "&" character or the end of the target request string to ensure that the matched "debug=" is at the end of the target request string or followed by an "&" character, that is, ensuring that the "debug=" parameter can be completely extracted; "i" is the flag of the regular expression.
[0086] In an embodiment, parse the target request based on the above preset regular expression to obtain the target parameter.
[0087] Step S3022: Determine the target address based on the target parameter.
[0088] In an embodiment of the present invention, if the target parameter includes a Uniform Resource Locator (URL), it indicates that the user has specified a switched back-end proxy environment in the target request. Therefore, the included Uniform Resource Locator is used as the target address. If the target parameter does not include a Uniform Resource Locator (URL), it indicates that the user has not specified a switched back-end proxy environment in the target request. At this time, the default back-end proxy environment set in the environment switching plug-in can be used as the switching object, and accordingly, a preset address is obtained from the configuration information of the environment switching plug-in. The back-end proxy environment corresponding to the preset address is the default back-end proxy environment, and this preset address is used as the target address.
[0089] Step S303: Invoke the proxy service in the environment switching plug-in, and forward the target request to the target environment based on the target address, so as to switch the proxy environment to the target environment. For details, please refer to Figure 1 Step S103 of the embodiment shown, which will not be elaborated here.
[0090] The proxy environment switching method provided by the embodiment of the present invention parses the target request based on a regular expression, extracts the target parameter, thereby determines the target address corresponding to the target request according to the target parameter, and forwards the target request to the target environment corresponding to the target address. Thus, only by modifying the address in the target parameter in the target request, it is possible to switch to the required back-end proxy environment without changing the configuration file, restarting the project and the server, thereby improving the development efficiency.
[0091] In this embodiment, a proxy environment switching device is further provided. This device is used to implement the above-mentioned embodiment and the preferred implementation manner, and those that have been described will not be elaborated again. As used below, the term "module" can be a combination of software and / or hardware that can achieve a predetermined function. Although the device described in the following embodiments is preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.
[0092] This embodiment provides a proxy environment switching device, as Figure 4 shown, including:
[0093] A plug-in startup module 401, which is used to introduce the environment switching plug-in into the configuration file of the current development service, and configure and start the environment switching plug-in; the environment switching plug-in is built based on the vite architecture;
[0094] An address extraction module 402, which is used to respond to the target request entering the current development service, invoke the middleware function in the environment switching plug-in, perform parameter parsing and extraction on the target request, and obtain the target address; the request type of the target request is the target type, and the target type is the request type that triggers the environment switching plug-in to perform environment switching;
[0095] The environment switching module 403 is used to call the proxy service in the environment switching plugin and forward the target request to the target environment based on the target address, so as to switch the proxy environment to the target environment.
[0096] In an optional implementation manner, the plugin startup module 401 includes:
[0097] The configuration information reading unit is used to read the configuration information of the environment switching plugin from the configuration file in response to the update of the configuration information of the environment switching plugin, so as to configure the environment switching plugin;
[0098] The middleware function creating unit is used to create a middleware function through a hook function and add the middleware function to the current development service;
[0099] The proxy service creating unit is used to create a proxy service through a service creation method.
[0100] In an optional implementation manner, the middleware function creating unit includes:
[0101] The function registration subunit is used to register a hook function and generate a server instance of the current development service;
[0102] The middleware function creating subunit is used to call the middleware adding method of the server instance in the hook function to create a middleware function;
[0103] The middleware function adding subunit is used to add the middleware function to the server instance.
[0104] In an optional implementation manner, the address extraction module 402 includes:
[0105] The target request parsing unit is used to parse the target request based on a preset regular expression and extract the target parameter in the target request; the preset regular expression is used to locate the parameter at the target position in the target request;
[0106] The target address determining unit is used to determine the target address based on the target parameter.
[0107] In an optional implementation manner, the target address determining unit is used to:
[0108] If the target parameter contains a uniform resource locator, the included uniform resource locator is used as the target address;
[0109] If the target parameter does not contain a uniform resource locator, a preset address is obtained from the configuration information of the environment switching plugin and used as the target address.
[0110] In an optional implementation manner, the environment switching module 403 includes:
[0111] An encryption verification unit, configured to perform encryption verification on a target request based on the configuration information of an environment switching plugin if the target request is encrypted.
[0112] A target request forwarding unit, configured to forward the target request to a target address to forward the target request to a target environment.
[0113] In an optional implementation manner, an error event listener for listening to a proxy service is further provided in the environment switching plugin; the apparatus further includes:
[0114] An error event listening module, configured to listen to the process of forwarding the target request to the target address through the error event listener.
[0115] An error message returning unit, configured to return an error message corresponding to the error event if an error event is listened.
[0116] The further function descriptions of the above-mentioned modules and units are the same as those in the corresponding embodiments above, and will not be repeated here.
[0117] The traffic data processing apparatus and the model training apparatus in this embodiment are presented in the form of functional units. Here, the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and a memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0118] The embodiment of the present invention further provides a computer device having the above Figure 3 shown proxy environment switching apparatus.
[0119] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of a computer device provided by an optional embodiment of the present invention, as Figure 5As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting the components, including a high-speed interface and a low-speed interface. Each component communicates with each other using different buses and can be installed on a common motherboard or installed in other ways as needed. The processor can process instructions executed within the computer device, including instructions stored in the memory or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In some alternative embodiments, if needed, multiple processors and / or multiple buses can be used together with multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (such as an array of servers, a set of blade servers, or a multi-processor system). Figure 5 In the figure, a processor 10 is taken as an example.
[0120] The processor 10 can be a central processing unit, a network processor, or a combination thereof. Among them, the processor 10 can further include a hardware chip. The above-mentioned hardware chip can be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The above-mentioned programmable logic device can be a complex programmable logic device, a field-programmable gate array, a generic array logic, or any combination thereof.
[0121] Among them, the memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiments.
[0122] The memory 20 can include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the computer device. In addition, the memory 20 can include a high-speed random access memory and can also include a non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage devices. In some alternative embodiments, the memory 20 can optionally include a memory remotely set relative to the processor 10, and these remote memories can be connected to the computer device through a network. Examples of the above-mentioned network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0123] The memory 20 can include a volatile memory, such as a random access memory; the memory can also include a non-volatile memory, such as a flash memory, a hard disk, or a solid-state drive; the memory 20 can also include a combination of the above types of memories.
[0124] The computer device further includes a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0125] Embodiments of the present invention also provide a computer-readable storage medium. The method according to the embodiments of the present invention can be implemented in hardware, firmware, or be implemented as computer code that can be recorded on a storage medium, or be implemented as computer code that is originally stored in a remote storage medium or a non-transitory machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, or a solid-state drive, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by the computer, the processor, or the hardware, the method shown in the above embodiments is implemented.
[0126] A part of the present invention can be applied as a computer program product, such as computer program instructions. When executed by a computer, through the operation of the computer, the methods and / or technical solutions according to the present invention can be invoked or provided. Those skilled in the art should be able to understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executes the instructions, or the computer compiles the instructions and then executes the corresponding compiled program, or the computer reads and executes the instructions, or the computer reads and installs the instructions and then executes the corresponding installed program. Herein, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible by the computer.
[0127] Although the embodiments of the present invention are described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations all fall within the scope defined by the present invention.
Claims
1. A method for switching proxy environments, characterized in that, The method includes: Introduce an environment switching plugin into the configuration file of the current development service, and configure and start the environment switching plugin; the environment switching plugin is built based on the vite architecture; In response to a target request entering the current development service, call the middleware function in the environment switching plugin to parse and extract parameters from the target request to obtain a target address; the request type of the target request is a target type, and the target type is a request type that triggers the environment switching plugin to perform environment switching; Call the proxy service in the environment switching plugin, and forward the target request to the target environment based on the target address, so as to switch the proxy environment to the target environment.
2. The method according to claim 1, characterized in that, The configuring and starting the environment switching plugin includes: In response to an update of the configuration information of the environment switching plugin, read the configuration information of the environment switching plugin from the configuration file to configure the environment switching plugin; Create the middleware function through a hook function, and add the middleware function to the current development service; Create the proxy service through a service creation method.
3. The method according to claim 2, characterized in that The creating the middleware function through the hook function includes: Register the hook function and generate a server instance of the current development service; In the hook function, call the middleware addition method of the server instance to create a middleware function; Add the middleware function to the server instance.
4. The method according to claim 1, characterized in that, The parsing and extracting parameters from the target request to obtain a target address includes: Based on a preset regular expression, parse the target request to extract the target parameter in the target request; the preset regular expression is used to locate the parameter at the target position in the target request; Determine the target address based on the target parameter.
5. The method according to claim 4, wherein The determining the target address based on the target parameter includes: If the target parameter contains a uniform resource locator, use the included uniform resource locator as the target address; If the target parameter does not contain a uniform resource locator, obtain a preset address from the configuration information of the environment switching plugin, and use the preset address as the target address.
6. The method according to claim 1, wherein The forwarding the target request to the target environment based on the target address includes: If the target request is encrypted, perform encryption verification on the target request based on the configuration information of the environment switching plugin; Forward the target request to the target address to forward the target request to the target environment.
7. The method according to claim 1, wherein An error event listener for monitoring the proxy service is also set in the environment switching plugin; the method further includes: Monitor the process of forwarding the target request to the target address through the error event listener; If an error event is monitored, return the error information corresponding to the error event.
8. An agent environment switching device, characterized in that The device includes: A plugin startup module for introducing an environment switching plugin into the configuration file of the current development service, and configuring and starting the environment switching plugin; the environment switching plugin is built based on the vite architecture; An address extraction module, configured to, in response to a target request for entering the current development service, call a middleware function in the environment switching plugin, perform parameter parsing and extraction on the target request, and obtain a target address; the request type of the target request is a target type, and the target type is a request type that triggers the environment switching plugin to perform environment switching. An environment switching module, configured to call a proxy service in the environment switching plugin, and forward the target request to a target environment based on the target address, so as to switch the proxy environment to the target environment.
9. A computer device, characterized in that, Including: A memory and a processor, the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to execute the proxy environment switching method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Computer instructions are stored on the computer-readable storage medium, and the computer instructions are used to cause a computer to execute the proxy environment switching method according to any one of claims 1 to 7.