Application request processing method, device, equipment and medium based on Qiankun microservices
By uniformly processing 401 requests in the Qiankun microservice architecture, the main application intercepts and resends network requests carrying new tokens, solving the problem of inconsistent processing methods of sub-applications and improving user experience and operational efficiency.
Patent Information
- Application Number
- CN202410896084.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-07-05
AI Technical Summary
In the Qiankun microservice architecture, sub-applications do not handle 401 requests uniformly, resulting in poor user experience. When the token expires, users need to manually refresh the page or operate again.
Intercept the 401 requests of all sub-applications through the main application, pop up the login box uniformly and resend the request to ensure the consistency of user experience. Modify the Qiankun main application code to intercept the axios network response of the sub-application, and intercept the XMLHttpRequest attribute to obtain and save the network. Request parameters, recreate the network request to carry the new token.
It achieves a consistent user experience in different sub-applications, avoids the unconscious loss of access rights caused by token expiration, reduces the number of repeated logins, and improves user operation efficiency and system response speed.
Smart Images

Figure CN118449782B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology and provides a method, device, equipment and medium for processing application requests based on Qiankun microservices. Background Art
[0002] Qiankun Microservice is a front-end-oriented microservice architecture solution that splits complex front-end applications into multiple independent sub-applications. Each sub-application can be independently developed, tested, deployed and run, and can be combined into a complete front-end application. The main application is the entrance and control center of the entire micro-front-end architecture, responsible for loading and managing all sub-applications.
[0003] When the user login expires, a network request with a status code of 401 will be received. At this time, different sub-applications may have different processing methods. Some sub-applications will jump to the login page, while others will pop up a login prompt box. Users will encounter different processing methods in different sub-applications, resulting in a poor user experience. Summary of the invention
[0004] The present application provides an application request processing method, apparatus, device and medium based on Qiankun microservices, which are used to solve the problem of how to uniformly process 401 requests.
[0005] In a first aspect, a method for processing application requests based on Qiankun microservices is provided, which is applied to a main application, wherein the main application manages multiple sub-applications; the method comprises:
[0006] Intercepting a first return data request sent by the server; the first return data request is a response result of a first network request sent by any sub-application to the server;
[0007] If the status code in the first returned data request is 401, a login box pops up;
[0008] Log in according to the account and password entered by the user in the login box; the status code 401 indicates that the token requested by the first network has expired;
[0009] If the login is successful, a second network request carrying a new token is sent to the server; the parameter information of the second network request is the same as that of the first network request.
[0010] In an embodiment of the present application, the main application intercepts 401 requests sent to all sub-applications, and uniformly performs pop-up login, resend requests and other processing, which can ensure the user's consistent experience in different sub-applications and reduce user dissatisfaction caused by the inconsistent processing methods of sub-applications. When the token expires, a login box pops up immediately to remind the user that they need to log in again, avoiding the user from losing access rights without perception, and continuing the previous operation after the user provides the account number and password, avoiding the inconvenience of the user needing to manually refresh the page or re-operate because the token expires. This method is executed by the main application. Without changing the code of other sub-applications, you only need to modify the code of Qiankun's main application to implement the axios network response interception for each sub-application.
[0011] Optionally, the parameter information includes a request method, a uniform resource locator, and a request header.
[0012] In an embodiment of the present application, the second network request has the same method, uniform resource locator and request header as the first network request, except for the token. The server's response to the second network request can be returned to the sub-application as a response to the first network request.
[0013] Optionally, before intercepting the first return data request sent by the server, the method further includes:
[0014] Intercepting attributes in the static object XMLHttpRequest on the window instance; wherein the attributes are used to indicate parameter information of the network request; the network request includes the first network request;
[0015] The parameter information of the network request is saved.
[0016] In the embodiment of the present application, since each sub-application uses axios to perform network requests, and the underlying implementation logic of axios is network encapsulation based on XMLHttpRequest, by intercepting the attributes of XMLHttpRequest on the window instance of the main application, network interception of each sub-application can be achieved.
[0017] Optionally, the properties include an open method, a send method and a setRequestHeader method; the open method is used to initialize the network request; the send method is used to send the network request; and the setRequestHeader method is used to set a request header of the network request.
[0018] In an embodiment of the present application, the open method, the send method, and the setRequestHeader method are intercepted to obtain various parameter information of the network request, which is convenient for use in the subsequent re-creation of the network request.
[0019] Optionally, intercepting the first return data request sent by the server includes:
[0020] Intercept the onloadend method or onreadystatechange method in the static object XMLHttpRequest on the window instance;
[0021] If the status code in the first returned data request is 401, a login box pops up, including:
[0022] If the status code in the onloadend method or the onreadystatechange method is 401, a login box pops up.
[0023] In the embodiment of the present application, considering that different versions of axios use different callback methods when completing a request, both the onloadend method and the onreadystatechange method are intercepted, which can improve the compatibility of the code to adapt to different versions of axios.
[0024] Optionally, after intercepting the first return data request sent by the server, the method further includes:
[0025] If the status code in the first returned data request is not 401, the first returned data request is sent to any of the sub-applications.
[0026] In an embodiment of the present application, if the status code is not 401, it means that the token is valid and there is no need to re-request authentication or authorization. A response is directly returned to the corresponding sub-application, which can reduce the number of repeated requests to the authentication server, thereby improving the response speed and reducing user waiting time.
[0027] Optionally, if the login is successful, sending a second network request carrying a new token to the server includes:
[0028] If the login is successful, a new token is obtained;
[0029] Creating a second network request according to the new token and parameter information of the first network request;
[0030] Sending the second network request to the server.
[0031] In an embodiment of the present application, a second network request is created based on the new token and the parameter information of the first network request, so that the parameter information of the second network request is the same as that of the first network request but the token is different. The response to the second network request can be returned to the corresponding sub-application as the response to the first network request, which can simplify the logical implementation of the server and the sub-application. The sub-application does not need to care about which specific token initiated the request, but only needs to process the returned response.
[0032] Optionally, if the status code in the first returned data request is 401, a login box is popped up, including:
[0033] If the status code in the first returned data request is 401, a login box pops up and the first returned data request is put into an array;
[0034] intercepting a second return data request sent by the server, and if the status code in the second return data request is 401, placing the second return data request into the array;
[0035] If the login is successful, sending a second network request carrying a new token to the server includes:
[0036] If the login is successful, a second network request carrying a new token and a fourth network request carrying a new token are sent to the server; the parameter information of the fourth network request is the same as that of the third network request.
[0037] In an embodiment of the present application, multiple 401 requests are saved in an array, and after waiting for successful login, the corresponding network request is recreated and sent according to each 401 request in the array. In this way, the user only needs to log in again once, which can reduce the number of repeated logins of the user and improve the user's operating efficiency.
[0038] Optionally, if the login is successful, after sending a second network request carrying a new token to the server, the method further includes:
[0039] Synchronize the state of the second network request to the first network request;
[0040] The state of the fourth network request is synchronized with the third network request.
[0041] In the embodiment of the present application, the status of the first network request and the third network request is always in a waiting state. In this way, although the network request is resent, for the user on the web page, there is only one perceived request, which can reduce the user's negative perception of system performance and response speed.
[0042] Optionally, if the login is successful, after sending a second network request carrying a new token to the server, the method further includes:
[0043] intercepting a third return data request sent by the server; the third return data request being a response to the second network request;
[0044] If the status code in the third return data request is not 401, the third return data request is sent to any of the sub-applications.
[0045] In an embodiment of the present application, forwarding the response to the second network request to the corresponding sub-application can ensure that the user can obtain the required data and improve the user experience.
[0046] In a second aspect, an application request processing device based on Qiankun microservice is provided, which is arranged in a main application, and the main application manages multiple sub-applications; the device comprises:
[0047] An interception module, used for intercepting a first return data request sent by a server; the first return data request is a response result of a first network request sent by any sub-application to the server;
[0048] A pop-up module, configured to pop up a login box if the status code in the first returned data request is 401;
[0049] A login module, used to log in according to the account and password entered by the user in the login box; the status code 401 indicates that the token of the first network request has expired;
[0050] The sending module is used to send a second network request carrying a new token to the server if the login is successful; the parameter information of the second network request is the same as that of the first network request.
[0051] In a third aspect, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the application request processing method based on Qiankun microservices as described in any one of the first aspects.
[0052] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and a processor executes the computer program to implement the application request processing method based on Qiankun microservices as described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Attached Figure 1 A schematic diagram of the computer device structure of the hardware operating environment involved in the embodiments of the present application;
[0054] Attached Figure 2 A flowchart of an application request processing method based on Qiankun microservices provided in an embodiment of the present application;
[0055] Attached Figure 3 A schematic diagram of the sending process of a network request provided in an embodiment of the present application;
[0056] Attached Figure 4 A schematic diagram of the processing flow of the loop function provided in an embodiment of the present application;
[0057] Attached Figure 5 A schematic diagram of the structure of an application request processing device based on Qiankun microservices provided in an embodiment of the present application.
[0058] Markings in the accompanying drawings: 101 - processor, 102 - communication bus, 103 - network interface, 104 - user interface, 105 - memory. DETAILED DESCRIPTION
[0059] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0060] In order to uniformly process 401 requests, the present application embodiment provides an application request processing method based on Qiankun microservices, which can be executed by a computer device. Figure 1 , which is a schematic diagram of the computer device structure of the hardware operating environment involved in the embodiment of the present application.
[0061] The computer device may include: a processor 101, such as a central processing unit (CPU), a communication bus 102, a network interface 103, a user interface 104, and a memory 105. The communication bus 102 is used to realize the connection and communication between these components. The user interface 104 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the user interface 104 may also include a standard wired interface and a wireless interface. The network interface 103 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (WIreless-FIdelity, WI-FI) interface). The memory 105 may optionally be a storage device independent of the aforementioned processor 101. The memory 105 may be a high-speed random access memory (RAM) memory, or it may be a stable non-volatile memory (NVM), such as at least one disk storage. The processor 101 may be a general-purpose processor, including a central processing unit, a network processor, etc., or it may be a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component.
[0062] Those skilled in the art will appreciate that Figure 1 The structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine some components, or arrange the components differently.
[0063] As attached Figure 1 As shown, the memory 105 as a storage medium may include an operating system, a network communication module, a user interface module, and an application request processing device based on Qiankun microservices.
[0064] In the attached Figure 1 In the computer device shown, the network interface 103 is mainly used for data communication with the network server; the user interface 104 is mainly used for data interaction with the user; the processor 101 and the memory 105 in the present application can be set in the computer device, and the computer device calls the application request processing device based on Qiankun microservices stored in the memory 105 through the processor 101, and executes the application request processing method based on Qiankun microservices provided in the embodiment of the present application.
[0065] Refer to the attached Figure 2 Based on the hardware device of the aforementioned embodiment, the embodiment of the present application provides an application request processing method based on Qiankun microservices, comprising the following steps:
[0066] S201. Intercept a first return data request sent by a server.
[0067] The first returned data request is a response result of a first network request sent by any sub-application to the server.
[0068] In the specific implementation process, any sub-application can initiate a first network request to the server. The first network request includes the uniform resource locator (URL) to be accessed, the request method (Request Method), and the request header. The uniform resource locator (URL) is a string used to identify and locate resources on the Internet. The request method is used to define the type of operation performed by the client on the server. When the first network request is an HTTP request, the request method includes a get request and a post request. The get request is used to obtain resources from the server, and the post request is used to submit data to the server. The request header contains metadata and other additional information about the request. When the first network request is an HTTP request and the request method used is a post request, the network request also includes a request body, which contains data that needs to be submitted to the server.
[0069] After receiving the first network request, the server will parse the first network request and perform corresponding processing according to the content of the request. After processing, it will generate a first return data request, which includes a status code, a response header, and a response body, and send the first return data request to the corresponding sub-application. The main application can intercept the first return data request sent by the server to the sub-application.
[0070] In a possible embodiment, before executing S201, the attributes in the static object XMLHttpRequest are intercepted on the window instance; wherein the attributes are used to indicate parameter information of a network request, and the network request includes a first network request; and the parameter information of the network request is saved.
[0071] In the specific implementation process, since each sub-application uses axios for network requests, and the underlying implementation logic of axios is based on the network encapsulation of XMLHttpRequest, the attributes of XMLHttpRequest can be intercepted on the window of the main application, thereby realizing network interception for each sub-application.
[0072] Among them, the properties include open method, send method and setRequestHeader method; the open method is used to initialize the network request, including the request method, uniform resource locator, etc. The send method is used to send the network request. If it is an asynchronous request (the default is asynchronous request), this method will return immediately after the request is sent. If it is a synchronous request, this method will not return until the response arrives. The setRequestHeader method is used to set the request header of the network request, such as the value of the token. The latest token is reset for each request.
[0073] S202: If the status code in the first returned data request is 401, a login box pops up.
[0074] In the specific implementation process, when a user logs in, the server will generate a token for the sub-application. The token is usually an encrypted string that is used to identify the user and authenticate the user in subsequent requests. The token has a certain validity period. During this validity period, the user can use the token to access protected resources. Once the validity period of the token ends, the server will consider the token expired, that is, it will no longer accept access requests with the token.
[0075] After intercepting the first return data request, the first return data request can be parsed to obtain the value of the status code. If the status code is 401, it means that the token of the first network request has expired, that is, the validity period of the token has ended, and a login box pops up. The login box is a user interface element used to collect user authentication information, including account number and password, so that the user can log in to the application or website.
[0076] In a possible embodiment, the onloadend method or onreadystatechange method in the static object XMLHttpRequest is intercepted on the window instance; the onloadend method and the onreadystatechange method are both callback methods for completing network requests; if the status code in the onloadend method or the onreadystatechange method is 401, a login box pops up.
[0077] In the specific implementation process, the network request completion callback method includes the onloadend method and the onreadystatechange method. Among them, the onloadend method is triggered after the loading progress of a resource stops, and the onreadysttatechange method is triggered when the readyState attribute of the XMLHttpRequest object changes, that is, when the status of the request changes, the corresponding processing function will be called.
[0078] Lower versions of axios only have onreadystatechange methods, but no onloadend methods, while higher versions of axios use onreadystatechange or onloadend methods. Therefore, the onreadystatechange or onloadend methods are intercepted to adapt to different versions of axios.
[0079] S203: Log in according to the account number and password entered by the user in the login box.
[0080] During the specific implementation process, the user re-enters the account and password in the login box, and the server will verify the account and password provided by the user. If the verification passes, a new token for identity authentication will be regenerated, and a response carrying the new token will be sent to any sub-application.
[0081] S204: If the login is successful, send a second network request carrying a new token to the server.
[0082] In a possible embodiment, if the login is successful, a new token is obtained, and a second network request is created according to the new token and parameter information of the first network request; and the second network request is sent to the server.
[0083] During the specific implementation process, if the user logs in successfully, it means that the account and password verification is passed. The main application can intercept the response carrying the new token, and create a new network request, namely the second network request, based on the new token and the saved parameter information of the first network request (including the request method, uniform resource locator, etc.), and send the second network request to the server.
[0084] In an embodiment of the present application, the parameter information of the second network request is the same as that of the first network request. The response to the second network request can be returned to the corresponding sub-application as the response to the first network request, which can simplify the logical implementation of the server and the sub-application. The sub-application does not need to care about which token initiated the request, but only needs to process the returned response.
[0085] In a possible embodiment, after intercepting the first return data request sent by the server, if the status code in the first return data request is not 401, the first return data request is sent to any sub-application.
[0086] During the specific implementation process, if the status code in the first returned data request is not 401, for example: 200 (successful request), 301 (the requested resource has been permanently moved to the new URI), 404 (the requested resource was not found), etc., it means that the token is still valid and there is no need to re-request. The first returned data request is directly released to improve the response speed and reduce the user waiting time.
[0087] In a possible embodiment, if the status code in the first returned data request is 401, a login box pops up, including:
[0088] If the status code in the first returned data request is 401, a login box pops up and the first returned data request is put into an array;
[0089] intercepting a second return data request sent by the server, and if the status code in the second return data request is 401, placing the second return data request into the array;
[0090] If the login is successful, a second network request with a new token is sent to the server, including:
[0091] If the login is successful, a second network request carrying a new token and a fourth network request carrying a new token are sent to the server; the parameter information of the fourth network request is the same as that of the third network request.
[0092] In the specific implementation process, considering that the user login process takes time, the second return data request with status code 401 may be received in succession during this time period. Therefore, the main application first saves the first return data request with status code 401 and the second return data request in an array, waits for the user to successfully re-login, and then extracts the parameter information of the first network request according to the first return data request, and creates the second network request according to the new token and the parameter information of the first network request. Extract the parameter information of the third network request according to the second return data request, and create the fourth network request according to the new token and the parameter information of the third network request. Finally, send the second network request and the fourth network request together to the server, so that the user only needs to re-login once to resend multiple network requests, reduce the number of repeated logins of the user, and improve the user's operation efficiency.
[0093] In a possible embodiment, after executing S204, the state of the second network request is synchronized to the first network request; and the state of the fourth network request is synchronized to the third network request.
[0094] In the specific implementation process, the status of the first network request and the third network request is always in a waiting state, that is, the network request sent by the sub-application is always in a waiting state, but for the user on the web page, there is only one perceived request, which can reduce the user's negative perception of system performance and response speed.
[0095] In a possible embodiment, after executing S204, a third return data request sent by the server is intercepted; the third return data request is a response to the second network request; if the status code in the third return data request is not 401, the third return data request is sent to any sub-application.
[0096] During the specific implementation process, the main application sends a second network request carrying a new token to the server. The server responds to the second network request and returns a third return data request carrying the response result. After the main application intercepts the third return data request, if the status code in the third return data request is still 401, S202-S204 will continue to be executed until the status code in the intercepted third return data request is not 401, and the third return data request will be sent to the corresponding sub-application.
[0097] The following introduces the specific implementation steps of an application request processing method based on Qiankun microservices provided in an embodiment of the present application.
[0098] S1.1. Intercept the send, open, and setRequestHeader attributes in XMLHttpRequest on the window instance.
[0099] The code example is as follows:
[0100] const send=window.XMLHttpRequest.prototype.send;
[0101] const open=window.XMLHttpRequest.prototype.open;
[0102] const setRequestHeader=window.XMLHttpRequest.prototype.setRequestHeade;
[0103] This code means that three constants send, open and setRequestHeader are defined, which point to the send, open and setRequestHeader methods under the window.XMLHttpRequest.prototype object respectively. In other words, the values of these three constants are the corresponding property values of the static object XMLHttpRequest on the window.
[0104] S1.2. Re-implement the parameter passing of the open method.
[0105] In S1.1, three variables send, open, and setRequestHeader are defined. Their values are the property values of the object XMLHttpRequest on the window. The open property of XMLHttpRequest is set to a function again. Before returning the open.call method, the obtained function parameters are saved to the openParams property of the XMLHttpRequest object to facilitate the subsequent use of resending the request. Then the native method open.call() of XMLHttpRequest is called and the parameters are passed in.
[0106] S1.3. Reimplement the send method.
[0107] The reimplementation of the send method is similar to the reimplementation of the open method. Three variables have been declared in S1.1, and their values are assigned to the corresponding attribute values of XMLHttpRequest. The send method of XMLHttpRequest is then set to a function again, and the native method send is called in the last part of this function, that is, the variables in S1.1 are called.
[0108] In the send method, the onloadend and onreadystatechange methods in axios are rewritten. In the send function, there is more judgment logic on whether the onreadystatechange and onloadend methods exist, because in the lower version of axios, the onloadend method may be used for the request sending completion callback, while in the higher version of axios, onreadystatechange or onloadend will be used for the request sending completion callback.
[0109] S1.4. Implement the 401 logic processing of the loop function.
[0110] When the network request returns a 401 promise request, intercept the 401 promise request and prevent the request from being rejected and resolved, that is, do not modify the status of the promise request, and then pop up a re-login box. After the user logs in successfully, send another network request based on the request header and request parameters of the previous 401 status. When this network request is successful, use the response result of this network request as the result of the 401 request.
[0111] Please refer to the attached Figure 3 , is a schematic diagram of the network request sending process provided in an embodiment of the present application.
[0112] First, set the network request header (setRequestHeader), then execute the connection request (open) method, execute the send request (send) method after the connection is successful, and then determine whether there is an onloadend method on the XMLHttpRequest object. If so, call the onloadend method, if not, call the onreadystatechange method. Finally, execute the loop function to intercept the callback of the network request completion in XMLHttpRequest, that is, the onloadend method or the onreadystatechange method.
[0113] Please refer to the attached Figure 4 , which is a processing flow chart of the loop function provided in an embodiment of the present application.
[0114] Intercept promise1 of the 401 request returned in the onloadend method or onreadystatechange method, keep promise1 in the pending state, then pop up the login box, log in according to the account and password, and after successful login, send the request (promise2) again. All request parameters of promise2 and promise1 are the same. If the return result of the waiting request is still 401, the login box will continue to pop up. If it is not 401, synchronize the state of promise2 to promise1. Promise1 is either fulfilled or rejected. The fulfilled state means that the asynchronous operation is successfully completed and a value is returned. The rejected state means that the asynchronous operation failed or an error was encountered. Finally, modify the page state.
[0115] In summary, the embodiment of the present application provides an application request processing method based on Qiankun microservices, which only modifies the code of the main application to implement network interception of the sub-application in the microservice. The 401 response of the first network request is intercepted, and after the login is successful, the second network request is resent, and the status of the second network request is synchronized with the first network request. In this way, the perception on the web page is that the first network request has been in a waiting state, and the request is terminated only after the login is successful.
[0116] Based on the same inventive concept, please refer to the attached Figure 5 The embodiment of the present application also provides an application request processing device based on Qiankun microservices, which is set in a main application, and the main application manages multiple sub-applications; the device includes:
[0117] An interception module, used to intercept a first return data request sent by the server; the first return data request is a response result of a first network request sent by any sub-application to the server;
[0118] A pop-up module, used to pop up a login box if the status code in the first returned data request is 401;
[0119] A login module is used to log in according to the account and password entered by the user in the login box; a status code of 401 indicates that the token requested by the first network has expired;
[0120] The sending module is used to send a second network request carrying a new token to the server if the login is successful; the parameter information of the second network request is the same as that of the first network request.
[0121] It should be noted that each module in the application request processing device based on Qiankun microservice in this embodiment corresponds one-to-one to each step in the data query method based on cache preheating in the aforementioned embodiment. Therefore, the specific implementation of this embodiment can refer to the implementation of the aforementioned method, which will not be repeated here.
[0122] Based on the same inventive concept, the present application also provides a computer device, which includes a processor, a memory, and a computer program stored in the memory. When the computer program is executed by the processor, it implements the aforementioned application request processing method based on Qiankun microservices.
[0123] Based on the same inventive concept, the present application also provides a computer storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the aforementioned application request processing method based on Qiankun microservices is implemented.
[0124] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or various devices including one or any combination of the above memories. The computer may be various computing devices including intelligent terminals and servers.
[0125] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0126] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file storing other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0127] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0128] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0129] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0130] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a multimedia terminal device (which can be a mobile phone, a computer, a television receiver, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0131] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for processing application requests based on Qiankun microservices, characterized in that: Applied in a main application, the main application manages multiple sub-applications; the method includes: Intercepting a first return data request sent by the server; the first return data request is a response result of a first network request sent by any sub-application to the server; If the status code in the first returned data request is 401, a login box pops up; the status code 401 indicates that the token of the first network request has expired; Log in according to the account and password entered by the user in the login box; If the login is successful, a second network request carrying a new token is sent to the server; the parameter information of the second network request is the same as that of the first network request; If the status code in the first returned data request is 401, a login box pops up, including: If the status code in the first returned data request is 401, a login box pops up and the first returned data request is put into an array; intercepting a second return data request sent by the server, and if the status code in the second return data request is 401, placing the second return data request into the array; the second return data request is a response result of the third network request sent by any sub-application to the server; If the login is successful, sending a second network request carrying a new token to the server includes: If the login is successful, a second network request carrying a new token and a fourth network request carrying a new token are sent to the server; the parameter information of the fourth network request is the same as that of the third network request.
2. The application request processing method based on Qiankun microservices according to claim 1, characterized in that: The parameter information includes the request method, the uniform resource locator and the request header.
3. The application request processing method based on Qiankun microservices according to claim 1, characterized in that: Before intercepting the first return data request sent by the server, the method further includes: Intercepting attributes in the static object XMLHttpRequest on the window instance; wherein the attributes are used to indicate parameter information of the network request; the network request includes the first network request; The parameter information of the network request is saved.
4. The application request processing method based on Qiankun microservices according to claim 3, characterized in that: The properties include an open method, a send method and a setRequestHeader method; the open method is used to initialize a network request; the send method is used to send a network request; and the setRequestHeader method is used to set a request header for a network request.
5. The application request processing method based on Qiankun microservices according to claim 1, characterized in that: The interception of the first return data request sent by the server includes: Intercept the onloadend method or onreadystatechange method in the static object XMLHttpRequest on the window instance; If the status code in the first returned data request is 401, a login box pops up, including: If the status code in the onloadend method or the onreadystatechange method is 401, a login box pops up.
6. The application request processing method based on Qiankun microservices according to claim 1, characterized in that: After intercepting the first return data request sent by the server, the method further includes: If the status code in the first returned data request is not 401, the first returned data request is sent to any of the sub-applications.
7. The application request processing method based on Qiankun microservices according to claim 1, characterized in that: If the login is successful, sending a second network request carrying a new token to the server includes: If the login is successful, a new token is obtained; Creating a second network request according to the new token and parameter information of the first network request; Sending the second network request to the server.
8. The application request processing method based on Qiankun microservices according to claim 1, characterized in that: If the login is successful, after sending a second network request carrying a new token to the server, the method further includes: Synchronize the state of the second network request to the first network request; The state of the fourth network request is synchronized with the third network request.
9. The application request processing method based on Qiankun microservices according to claim 1, characterized in that: If the login is successful, after sending a second network request carrying a new token to the server, the method further includes: intercepting a third return data request sent by the server; the third return data request being a response to the second network request; If the status code in the third return data request is not 401, the third return data request is sent to any of the sub-applications.
10. An application request processing device based on Qiankun microservices, characterized in that: Set in a main application, the main application manages multiple sub-applications; the device includes: An interception module, used for intercepting a first return data request sent by a server; the first return data request is a response result of a first network request sent by any sub-application to the server; A pop-up module, used for popping up a login box if the status code in the first return data request is 401; the pop-up login box if the status code in the first return data request is 401, including: if the status code in the first return data request is 401, popping up a login box, and putting the first return data request into an array; intercepting a second return data request sent by the server, and if the status code in the second return data request is 401, putting the second return data request into the array; the second return data request is a response result of a third network request sent by any sub-application to the server; A login module, used to log in according to the account and password entered by the user in the login box; the status code 401 indicates that the token of the first network request has expired; A sending module, used for sending a second network request carrying a new token to the server if the login is successful; the second network request has the same parameter information as the first network request; if the login is successful, sending the second network request carrying the new token to the server, including: if the login is successful, sending the second network request carrying the new token and a fourth network request carrying the new token to the server; the fourth network request has the same parameter information as the third network request.
11. A computer device, characterized in that: The computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the application request processing method based on Qiankun microservices as described in any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the processor executes the computer program to implement the application request processing method based on Qiankun microservices according to any one of claims 1 to 9.
