WO2021184824A1 - 基于应用程序接口网关的前后端分离方法及相关设备 - Google Patents
基于应用程序接口网关的前后端分离方法及相关设备 Download PDFInfo
- Publication number
- WO2021184824A1 WO2021184824A1 PCT/CN2020/132351 CN2020132351W WO2021184824A1 WO 2021184824 A1 WO2021184824 A1 WO 2021184824A1 CN 2020132351 W CN2020132351 W CN 2020132351W WO 2021184824 A1 WO2021184824 A1 WO 2021184824A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- gateway device
- access request
- virtual directory
- request
- path
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/4401—Bootstrapping
- G06F9/4406—Loading of operating system
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring for program initiating, e.g. using registry, configuration files
- G06F9/4451—User profiles; Roaming
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L41/00—Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
- H04L41/08—Configuration management of networks or network elements
- H04L41/0803—Configuration setting
- H04L41/0806—Configuration setting for initial configuration or provisioning, e.g. plug-and-play
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/34—Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters
Definitions
- This application relates to the field of computer networks, and in particular to a method, device, gateway device, and computer-readable storage medium for separating front and back ends based on an application program interface gateway.
- front-end pages and back-end services of the front-end and back-end monolithic architecture are placed in the same Java application, that is, the front-end static pages are packaged in a JAR package in the form of a resource directory.
- the inventor realizes that this method is difficult to maintain, and the JAR package must be repackaged when the front-end project is changed.
- front-end and back-end project developers must develop collaboratively in the same code base, and the front-end and back-end logic are coupled together, making front-end and back-end deployment and maintenance more difficult, and versions difficult to manage.
- the first aspect of the present application provides a front-end and back-end separation method based on an application program interface gateway, which is applied in a gateway device, and the method includes:
- the request is forwarded to the back-end microservice to obtain the dynamic resource, and the dynamic resource is returned to the front-end through the gateway device.
- the second aspect of the application provides a front-end and back-end separation device based on an application program interface gateway, the device including:
- the initialization module is used to obtain the configuration information of the gateway device, the virtual directory published by the front-end and the static resource compression package from the multi-tenant configuration center that is in communication with the gateway device, download the static resource compression package and decompress it to the The local of the gateway device to initialize the gateway device;
- the first access module is configured to receive a first access request for static resources sent by the browser of the front-end to the gateway device after initialization, and match the path of the virtual directory of the front-end according to the path of the first access request. Path, and when the path of the first access request matches the path of the front-end virtual directory, the first access request is sent to the front-end virtual directory, and the first access request is searched for the The front-end virtual directory, and return the front-end pages and static file content to the front-end browser; and
- the second access module is configured to receive a second access request requesting dynamic resources sent by the front-end to the gateway device after initialization, and trigger a request to call the back-end API according to the second access request, through the gateway device.
- the called back-end API request is forwarded to the back-end microservice to obtain the dynamic resource, and the dynamic resource is returned to the front-end through the gateway device.
- a third aspect of the present application provides a gateway device, wherein: the gateway device includes a processor and a memory, and the processor is configured to execute computer-readable instructions stored in the memory to implement the following steps:
- the request is forwarded to the back-end microservice to obtain the dynamic resource, and the dynamic resource is returned to the front-end through the gateway device.
- a fourth aspect of the present application provides a computer-readable storage medium having computer-readable instructions stored thereon, wherein the computer-readable instructions implement the following steps when executed by a processor:
- the request is forwarded to the back-end microservice to obtain the dynamic resource, and the dynamic resource is returned to the front-end through the gateway device.
- the gateway device connected to the multi-tenant configuration center supports multi-tenant access to the PG database, and obtains front-end virtual directories and static resource compression packages through the multi-tenant configuration center. Users apply for the PG database separately, causing resource waste and excessive consumption of front-end and back-end development costs.
- the gateway device can be used as a static resource server to automatically download, decompress, and route matching static resource compressed packages. Therefore, there is no need to purchase and deploy static resource servers separately, nor do users need to manually deploy them.
- the front-end static resource code saves the process of manually deploying static resources, and solves the difficult and difficult-to-manage problems of front-end and back-end deployment and maintenance.
- Fig. 1 is a flowchart of a front-end and back-end separation method based on an application program interface gateway in an embodiment of the present application.
- Fig. 2 is a schematic diagram of an application environment of a front-end and back-end separation method based on an application program interface gateway in an embodiment of the present application.
- Fig. 3 is a schematic diagram of a front-end and back-end separation device based on an application program interface gateway in an embodiment of the present application.
- Fig. 4 is a schematic diagram of a gateway device in an embodiment of the present application.
- the front-end and back-end separation method based on the application program interface gateway of this application is applied to one or more electronic devices.
- the electronic device is a device that can automatically perform numerical calculation and/or information processing in accordance with pre-set or stored instructions. Its hardware includes, but is not limited to, a microprocessor and an application specific integrated circuit (ASIC) , Programmable Gate Array (Field-Programmable Gate Array, FPGA), Digital Processor (Digital Signal Processor, DSP), embedded equipment, etc.
- ASIC application specific integrated circuit
- FPGA Field-Programmable Gate Array
- DSP Digital Processor
- embedded equipment etc.
- Fig. 1 is a flowchart of a front-end and back-end separation method based on an application program interface gateway in an embodiment of the present application. According to different needs, the order of the steps in the flowchart can be changed, and some steps can be omitted.
- the front-end and back-end separation method based on the application program interface gateway specifically includes the following steps:
- step S11 the virtual directory of the front end 2 and the static resource compressed package are stored in the PG database configured by the gateway device 1, wherein the virtual directory stores the project file of the front end 2 and the compressed file of the project file.
- FIG. 2 shows an application environment diagram of a front-end and back-end separation method based on an application program interface gateway in an embodiment of this application.
- the front-end and back-end separation method based on the application program interface gateway is applied in the gateway device 1.
- the gateway device 1 is communicatively connected with the front end 2, the back end 3 and the cloud platform 4 through a network.
- the front end 2 is a device with a browser.
- the front end 2 shown is a terminal device such as a notebook computer, a tablet computer, or a smart phone.
- the back end 3 is a server device.
- the cloud platform 4 is a cloud server.
- a first table and a second table are added to the PG database.
- the first table is used to store the project file of the front end 2 and the second table is used to store the compressed file of the project.
- the PG database is set in the PaaS service layer of the cloud platform 4.
- the gateway device 1 configures and stores the project files of the first table and the second table and the compressed files of the project files in the PG database of the PaaS service layer of the cloud platform 4.
- the project file includes a project identification number, a file name, a file path, a disable/enable mark, a creation time mark, and an update time mark.
- the compressed file of the project file includes a file identification number, file name, file type, file content, file size, version, corresponding virtual directory, disable/open mark, creation time mark, and update time mark.
- Step S12 Obtain the configuration data of the gateway device from the multi-tenant configuration center communicatively connected with the gateway device, determine a target API from the Restful APIs managed by the configuration management of the gateway device 1, and use the target API to target the gateway device
- the configuration data of 1 is queried and modified, and the modified configuration data is stored in the PG database.
- the cloud platform 4 includes the KONG-PORTAL-ADMIN service function.
- the configuration data of the gateway device 1 is configured and managed on the management console Portal, and the target API pair of the KONG-PORTAL-ADMIN service of the cloud platform 4 is stored in the first table and the second table Query and modify the configuration data, and store the configuration data in the PG database of the cloud platform 4.
- the management control platform Portal provides a management interface, and configures and manages the gateway device 1 through the management interface.
- the gateway device 1 receives the operation of the management interface to perform configuration management on the gateway device 1.
- the operation of the management console Portal to configure and manage the gateway device 1 includes publishing the content of the front end 2 and managing the routing and forwarding configuration of the ingress traffic between the front end 2 and the back end 3.
- the data of the static resource compressed package of the front end 2 is uploaded to the PG database for storage through the management console Portal.
- by providing Restful APIs for configuration management of the gateway device 1, and querying and modifying the configuration data of the gateway device 1 through the Restful APIs it is convenient for the user to modify the configuration data of the gateway device 1.
- Step S13 Obtain the virtual directory and static resource compressed package issued by the front end 2 from the multi-tenant configuration center communicatively connected with the gateway device 1, download the static resource compressed package and decompress it to the local of the gateway device 1 for comparison.
- the gateway device 1 is initialized.
- a multi-tenant configuration center is developed and constructed through the Go language, and the multi-tenant configuration center is connected to the gateway device 1.
- the constructed multi-tenant configuration center can perform configuration query and storage of the configuration data of the gateway device 1 based on the multi-tenant.
- the gateway device 1 connected to the multi-tenant configuration center supports multi-tenant access to the PG database, and obtains the virtual directory and static resource compression package of the front-end 2 through the multi-tenant configuration center, so as to prevent users from being alone Apply for the PG database, causing a waste of resources.
- the gateway device 1 obtains the static resource compressed package from a multi-tenant configuration center communicatively connected with the gateway device 1, downloads the static resource compressed package and decompresses it to the local of the gateway device 1, It realizes the automatic download and decompression of static resource compressed packages, avoids the deployment of additional static resource servers to automatically download and decompress static resource compressed packages, and saves server resources and manual deployment processes.
- the gateway device 1 acquiring the configuration data of the gateway device 1, the virtual directory and the static resource compression package issued by the front end 2 from the multi-tenant configuration center communicatively connected with the gateway device 1 includes: through a cloud platform
- the KONG-PORTAL-ADMIN service function of 4 inserts the notification event that the user publishes and modifies the virtual directory or the front-end static resource compressed package in the database; the gateway device 1 monitors the notification event and detects the notification event Obtain the latest virtual directory and static resource compressed package from the multi-tenant configuration center, and update it locally.
- the configuration data of the gateway device 1 includes the routing relationship between the path of the first access request and the path of the virtual directory.
- Step S14 Receive a first access request for static resources sent by the browser of the front end 2 to the gateway device 1 after initialization, and match the path of the virtual directory of the front end 2 according to the path of the first access request , And when the path of the first access request matches the path of the virtual directory of the front end 2, the first access request is sent to the virtual directory of the front end 2, and the first access request is searched according to the first access request.
- the virtual directory of the front end 2 is described, and the page and static file content of the front end 2 are returned to the browser of the front end 2.
- the browser uses the HTTP protocol to send the first access request to request static resources.
- the gateway device 1 matches the path of the corresponding virtual directory of the front end 2 according to the path of the first access request.
- the first access request is forwarded to the virtual directory corresponding to the internal static site on port 5000 of the gateway device 1.
- the page and static file of the front end 2 are retrieved from the directory, and the retrieved content of the page and static file of the front end 2 is returned to the browser of the front end 2.
- the gateway device 1 returns an error message to the front end 2.
- the front end 2 receives the error message sent by the gateway device 1 and sends the first access request requesting static resources to the gateway device 1 again.
- the browser of the front end 2 receives the page and the static file content returned by the gateway device 1 after being rendered and analyzed by the browser, and then the rendering effect is obtained on the browser.
- the gateway device 1 can be used as a static resource server to automatically download, decompress, and route the static resource compressed package. Therefore, there is no need to purchase and deploy a static resource server separately, and no manual deployment by the user is required.
- the static resource code of the front end 2 saves the process of manually deploying static resources.
- the access traffic coming in from the 5000 port is monitored through the 5000 port; the first access request coming in the 5000 port is intercepted, and the path of the first access request is targeted Match the corresponding virtual directory path, send the first access request to the corresponding virtual directory of the front end 2, find the virtual directory of the front end 2 according to the first access request, and return the page and static status of the front end 2 File content to the front end 2.
- the configuration data of the gateway device 1 includes the gray-scale policy of the front-end 2.
- the method further includes: monitoring the first access request from port 5000 through port 5000; Intercept the first access request coming in from port 5000 and determine whether the first access request meets the requirements of the gray-scale policy; when the first access request meets the requirements of the gray-scale policy, target the first access request The path of an access request matches the corresponding virtual directory path, the first access request is sent to the corresponding virtual directory, the virtual directory is searched according to the first access request, and the page and static files of the front end 2 are returned The content is given to the browser of the front end 2.
- the gray scale strategy refers to setting different access rights for different front ends 2.
- Step S15 Receive a second access request requesting dynamic resources sent by the front-end 2 to the initialized gateway device 1, and trigger a request to call the back-end API according to the second access request.
- the called back-end API request is forwarded to the microservice of the back-end 3 to obtain the dynamic resource, and the dynamic resource is returned to the front-end 2 through the gateway device 1.
- the browser of the front end 2 uses the HTTP protocol to send the second access request to request dynamic resources.
- the gateway device 1 triggers the request to call the back-end API according to the forwarding route of the microservice request of the back-end 3 set in the gateway device 1, and forwards the request of the called back-end API to the back-end API through the gateway device 1.
- the microservice of the end 3 obtains the dynamic resource, and returns the dynamic resource to the browser of the front end 2 through the gateway device 1. In this way, in this case, the front-end 2 and the back-end 3 are completely separated through the gateway device 1.
- the front-end personnel only pay attention to the front-end code development and the publishing and management of the front-end page through the gateway device 1, and the back-end personnel only pay attention to the micro Development of the service code, and configure the corresponding route in the gateway device 1, and forward the back-end API request.
- the method further includes: judging whether the second access request sent by the browser of the front end 2 is a hyperlink request requesting access to the front end, and dividing the second access request into a hyperlink request and a non- Hyperlink request, where the hyperlink request means that the http request is generated by the hyperlink of an html interface corresponding to the http request, and the non-hyperlink request means that there is no hyperlink relationship with any html interface; if it is determined that the second If the access request is a hyperlink request, the address of the hyperlink request is redirected, and the redirected address is returned to the browser of the front end 2 so that the browser generates a new access request; the new request sent by the browser of the front end 2 is received And forward the new access request to the microservice of the corresponding backend 3; and receive the access response corresponding to the new access request returned by the backend 3, and return the access response to The browser of the front end 2.
- the hyperlink is essentially a part of a webpage, and it is an element that allows connections between other webpages or sites, and there is bound to be a problem of address redirection. If after the gateway device 1 receives the second access request sent by the browser of the front end 2, and determines that the second access request is a hyperlink request, the gateway device 1 does not directly forward the second access request to The corresponding microservice of the backend 3 obtains the corresponding resource, but redirects the request address of the second access request, and the access request after the address redirection is the access request directly forwarded by the gateway device 1.
- the gateway device 1 before determining whether the http request is a hyperlink request, the gateway device 1 also matches the http request with the pre-configured API of the gateway device 1. If the http request matches the pre-configured API successfully For example, it may be based on matching the uri of the http request with the pre-configured API, then the gateway device 1 forwards the http request to the address of the microservice of the backend 3 pointed to by the matching API to obtain the microservice of the backend 3 The resource returned by the service.
- the gateway device 1 determines whether the http request is a hyperlink request; if it is determined that the http request is a non-hyperlink request When the http request is determined as a request failure, and the resource returned by the back-end microservice cannot be obtained; if it is determined that the http request is a hyperlink request, the address of the hyperlink request is redirected.
- the gateway device 1 connected to the multi-tenant configuration center supports multi-tenant access to the PG database, and obtains the virtual directory and static resource compression package of the front-end 2 through the multi-tenant configuration center, so as to prevent users from being alone Apply for the PG database, causing a waste of resources.
- the gateway device 1 can be used as a static resource server to automatically download, decompress, and route matching static resource compressed packages. Therefore, there is no need to purchase and deploy a static resource server separately, and there is no need for users to manually deploy
- the static resource code of the front end 2 saves the process of manually deploying static resources.
- FIG. 3 is a schematic diagram of a front-end and back-end separation device 40 based on an application program interface gateway in an embodiment of the application.
- the front-end and back-end separation device 40 based on the application program interface gateway runs in the gateway device 1.
- the front-end and back-end separation device 40 based on the application program interface gateway may include a plurality of functional modules composed of program code segments.
- the program code of each program segment in the front-end and back-end separation device 40 based on the application program interface gateway may be stored in a memory and executed by at least one processor to perform the function of front-end and back-end separation.
- the front-end and back-end separation device 40 based on the application program interface gateway may be divided into multiple functional modules according to the functions it performs.
- the front-end and back-end separation device 40 based on the application program interface gateway may include a pre-storage module 401, a configuration module 402, an initialization module 403, a first access module 404, and a second access module 405.
- the module referred to in this application refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, and are stored in a memory. In some embodiments, the functions of each module will be detailed in subsequent embodiments.
- the pre-storage module 401 stores the virtual directory of the front end 2 and the compressed static resource package in the PG database configured by the gateway device 1, wherein the virtual directory stores the project file of the front end 2 and the compressed file of the project file.
- the pre-storage module 401 adds a first table and a second table to the PG database.
- the first table is used to store the project file of the front end 2, and the second table is used to store the project. Compressed files.
- the PG database is set in the PaaS service layer of the cloud platform 4.
- the pre-storage module 401 configures and stores the project files of the first table and the second table and compressed files of the project files in the PG database of the PaaS service layer of the cloud platform 4 through the gateway device 1.
- the project file includes a project identification number, a file name, a file path, a disable/enable mark, a creation time mark, and an update time mark.
- the compressed file of the project file includes a file identification number, file name, file type, file content, file size, version, corresponding virtual directory, disable/open mark, creation time mark, and update time mark.
- the configuration module 402 obtains the configuration data of the gateway device from the multi-tenant configuration center that is in communication with the gateway device, determines a target API from the Restful APIs managed by the configuration management of the gateway device 1, and uses the target API to The configuration data of the gateway device 1 is queried and modified, and the modified configuration data is stored in the PG database.
- the cloud platform 4 includes the KONG-PORTAL-ADMIN service function.
- the configuration module 402 configures and manages the configuration data of the gateway device 1 through the management console Portal, and stores it in the first table through the target API pair of the KONG-PORTAL-ADMIN service of the cloud platform 4 And the configuration data in the second table is queried and modified, and the configuration data is stored in the PG database of the cloud platform 4.
- the management control platform Portal provides a management interface
- the configuration module 402 configures and manages the gateway device 1 through the management interface.
- the gateway device 1 receives the operation of the management interface to perform configuration management on the gateway device 1.
- the operation of the management console Portal to configure and manage the gateway device 1 includes publishing the content of the front end 2 and managing the routing and forwarding configuration of the ingress traffic between the front end 2 and the back end 3.
- the data of the static resource compressed package of the front end 2 is uploaded to the PG database for storage through the management console Portal.
- by providing Restful APIs for configuration management of the gateway device 1, and querying and modifying the configuration data of the gateway device 1 through the Restful APIs it is convenient for the user to modify the configuration data of the gateway device 1.
- the initialization module 403 obtains the configuration data of the gateway device 1, the virtual directory published by the front end 2 and the static resource compression package from the multi-tenant configuration center that is in communication with the gateway device 1, downloads and decompresses the static resource compression package Go to the local of the gateway device 1 to initialize the gateway device 1.
- the initialization module 403 develops and constructs a multi-tenant configuration center through the Go language, and connects the multi-tenant configuration center to the gateway device 1.
- the constructed multi-tenant configuration center can perform configuration query and storage of the configuration data of the gateway device 1 based on multi-tenancy.
- the gateway device 1 connected to the multi-tenant configuration center supports multi-tenant access to the PG database, and obtains the virtual directory and static resource compression package of the front-end 2 through the multi-tenant configuration center, so as to prevent users from being alone Apply for the PG database, causing a waste of resources.
- the initialization module 403 obtains the static resource compressed package from a multi-tenant configuration center that is communicatively connected with the gateway device 1, downloads the static resource compressed package and decompresses it to the local of the gateway device 1, It realizes the automatic download and decompression of static resource compressed packages, avoids the deployment of additional static resource servers to automatically download and decompress static resource compressed packages, and saves server resources and manual deployment processes.
- the initialization module 403 obtains the virtual directory and static resource compressed package published by the front-end 2 from the multi-tenant configuration center that is in communication with the gateway device 1, including: the KONG-PORTAL-ADMIN service function of the cloud platform 4 Insert a notification event for the user to publish and modify the virtual directory or the front-end static resource compressed package in the database; the gateway device 1 monitors the notification event, and when the notification event is detected, the notification event is retrieved from the multi-tenant configuration center Get the latest virtual directory and static resource compression package, and update it to the local.
- the configuration data of the gateway device 1 includes the routing relationship between the path of the first access request and the path of the virtual directory.
- the first access module 404 receives a first access request for static resources sent by the browser of the front end 2 to the gateway device 1 after initialization, and matches the path of the front end 2 according to the path of the first access request.
- the path of the virtual directory and when the path of the first access request matches the path of the virtual directory of the front end 2, the first access request is sent to the virtual directory of the front end 2, according to the first
- the access request searches the virtual directory of the front end 2 and returns the page and static file content of the front end 2 to the browser of the front end 2.
- the browser uses the HTTP protocol to send the first access request to request static resources.
- the first access module 404 matches the path of the corresponding virtual directory of the front end 2 according to the path of the first access request.
- the first access request is forwarded to the virtual directory corresponding to the internal static site on port 5000 of the gateway device 1.
- the page and static file of the front end 2 are retrieved from the directory, and the retrieved content of the page and static file of the front end 2 is returned to the browser of the front end 2.
- the first access module 404 returns an error message to the front end 2.
- the front end 2 receives the error message sent by the gateway device 1 and sends the first access request requesting static resources to the gateway device 1 again.
- the browser of the front end 2 receives the page and the static file content returned by the first access module 404 after being rendered and analyzed by the browser, and then the rendering effect is obtained on the browser.
- the gateway device 1 can be used as a static resource server to automatically download, decompress, and route the static resource compressed package. Therefore, there is no need to purchase and deploy a static resource server separately, and no manual deployment by the user is required.
- the static resource code of the front end 2 saves the process of manually deploying static resources.
- the first access module 404 listens to the first access request from port 5000 through port 5000 in the Nginx configuration template of the gateway device 1, and performs the first access request from port 5000 Intercept, for the path of the first access request to match the corresponding virtual directory path, send the first access request to the virtual directory of the corresponding front end 2, find the virtual directory of the front end 2 according to the first access request, and Return the page and static file content of the front end 2 to the front end 2.
- the configuration data of the gateway device 1 includes the gray-scale policy of the front-end 2
- the first access module 404 further includes: monitoring the access traffic from port 5000 through port 5000; according to the gray-scale policy, Intercept the first access request from port 5000 and determine whether the first access request meets the requirements of the gray-scale policy; when the first access request meets the requirements of the gray-scale policy, the The path of the first access request matches the corresponding virtual directory path, the first access request is sent to the corresponding virtual directory, the virtual directory is searched according to the first access request, and the page and static state of the front end 2 are returned.
- the content of the file is given to the browser of the front end 2.
- the gray scale strategy refers to setting different access rights for different front ends 2.
- the second access module 405 receives a second access request requesting dynamic resources sent by the front-end 2 to the initialized gateway device 1, and triggers a request to call the back-end API according to the second access request.
- the gateway device 1 forwards the called back-end API request to the microservice of the back-end 3 to obtain the dynamic resource, and returns the dynamic resource to the front-end 2 through the gateway device 1.
- the browser of the front end 2 uses the HTTP protocol to send the second access request to request dynamic resources.
- the second access module 405 triggers the request to call the back-end API according to the forwarding route of the microservice request of the back-end 3 set in the gateway device 1, and forwards the request of the called back-end API through the gateway device 1.
- To the microservice of the back end 3 to obtain the dynamic resource and return the dynamic resource to the browser of the front end 2 through the gateway device 1. In this way, in this case, the front-end 2 and the back-end 3 are completely separated through the gateway device 1.
- the front-end personnel only pay attention to the front-end code development and the publishing and management of the front-end page through the gateway device 1, and the back-end personnel only pay attention to the micro Development of the service code, and configure the corresponding route in the gateway device 1, and forward the back-end API request.
- the second access module 405 is further configured to determine whether the second access request sent by the browser of the front end 2 is a hyperlink request requesting access to the front end, and divide the second access request into Hyperlink request and non-hyperlink request, among them, the hyperlink request means that the http request is generated by an html interface hyperlink corresponding to the http request, and the non-hyperlink request means that there is no hyperlink relationship with any html interface; if It is determined that the second access request is a hyperlink request, then the address of the hyperlink request is redirected, and the redirected address is returned to the browser of the front end 2 so that the browser generates a new access request; receiving the request of the front end 2 A new access request sent by the browser, and the new access request is forwarded to the microservice of the corresponding backend 3 through the gateway device 1; and an access response corresponding to the new access request returned by the backend 3 is received , And return the access response to the browser of the front end 2 through the gateway device 1.
- the hyperlink is essentially a part of a webpage, and it is an element that allows connections between other webpages or sites, and there is bound to be a problem of address redirection. If after the gateway device 1 receives the second access request sent by the browser of the front end 2, and determines that the second access request is a hyperlink request, the gateway device 1 does not directly forward the second access request to The corresponding microservice of the backend 3 obtains the corresponding resource, but redirects the request address of the second access request, and the access request after the address redirection is the access request directly forwarded by the gateway device 1.
- the second access module 405 before determining whether the http request is a hyperlink request, the second access module 405 also matches the http request with the pre-configured API of the gateway device 1. If the http request matches the pre-configured API If the matching is successful, for example, it may be based on matching the uri of the http request with the pre-configured API, then the second access module 405 forwards the http request to the address of the microservice of the backend 3 pointed to by the matching API to Get the resources returned by the microservice of backend 3.
- the second access module 405 determines whether the http request is a hyperlink request; if it is determined that the http request is a non-hyperlink request When the link request is made, the http request is determined to be a request failure, and the resource returned by the back-end microservice cannot be obtained; if it is determined that the http request is a hyperlink request, the address of the hyperlink request is redirected.
- the gateway device 1 connected to the multi-tenant configuration center supports multi-tenant access to the PG database, and obtains the virtual directory and static resource compression package of the front-end 2 through the multi-tenant configuration center, so as to prevent users from being alone Apply for the PG database, causing a waste of resources.
- the gateway device 1 can be used as a static resource server to automatically download, decompress, and route matching static resource compressed packages. Therefore, there is no need to purchase and deploy a static resource server separately, and there is no need for users to manually deploy
- the static resource code of the front end 2 saves the process of manually deploying static resources.
- FIG. 4 is a schematic diagram of the gateway device 1 in an embodiment of this application.
- the gateway device 1 includes a memory 20, a processor 30, and a computer program 40 that is stored in the memory 20 and can run on the processor 30.
- the processor 30 executes the computer program 40, the steps in the embodiment of the method for separating the front and back ends based on the application program interface gateway are implemented, such as steps S11 to S15 shown in FIG. 1.
- the processor 30 executes the computer program 40, the functions of the modules/units in the foregoing embodiment of the front-end and back-end separation device based on the application program interface gateway are realized, for example, the modules 401 to 405 in FIG. 3.
- the computer program 40 may be divided into one or more modules/units, and the one or more modules/units are stored in the memory 20 and executed by the processor 30 to complete This application.
- the one or more modules/units may be a series of computer-readable instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 40 in the gateway device 1.
- the computer program 40 can be divided into the pre-storage module 401, the configuration module 402, the initialization module 403, the first access module 404, and the second access module 405 in FIG. 3.
- the specific functions of each module refer to the second embodiment.
- the gateway device 1 may be a server. Those skilled in the art can understand that the schematic diagram is only an example of the gateway device 1 and does not constitute a limitation on the gateway device 1. Components, for example, the gateway device 1 may also include an input/output device, a network access device, a bus, and the like.
- the so-called processor 30 may be a central processing module (Central Processing Unit, CPU), other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc.
- the general-purpose processor may be a microprocessor or the processor 30 may also be any conventional processor, etc.
- the processor 30 is the control center of the gateway device 1 and connects the entire gateway device 1 through various interfaces and lines. Parts.
- the memory 20 may be used to store the computer program 40 and/or modules/units.
- the processor 30 runs or executes the computer programs and/or modules/units stored in the memory 20, and calls the computer programs and/or modules/units stored in the memory 20.
- the data in 20 realizes various functions of the gateway device 1.
- the memory 20 may mainly include a program storage area and a data storage area.
- the program storage area may store an operating system, an application program required by at least one function (such as a sound playback function, an image playback function, etc.), etc.; the storage data area may Data (such as audio data) created in accordance with the use of the gateway device 1 and the like are stored.
- the memory 20 may include non-volatile memory and volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, and a flash memory card. (Flash Card), at least one disk storage device, flash memory device, or other storage device.
- the computer-readable storage medium may be non-volatile or volatile.
- the integrated module/unit of the gateway device 1 is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer readable storage medium.
- this application implements all or part of the processes in the above-mentioned embodiments and methods, and can also be completed by instructing relevant hardware through a computer program.
- the computer program can be stored in a computer-readable storage medium.
- the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file, or some intermediate forms.
- the computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory) , Random access memory, etc.
- the disclosed gateway device and method can be implemented in other ways.
- the embodiments of the gateway device described above are merely illustrative.
- the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
- the functional modules in the various embodiments of the present application may be integrated in the same processing module, or each module may exist alone physically, or two or more modules may be integrated in the same module.
- the above-mentioned integrated modules can be implemented in the form of hardware, or in the form of hardware plus software functional modules.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Computer And Data Communications (AREA)
Abstract
一种基于应用程序接口网关的前后端分离方法及相关设备。所述方法包括:从多租户配置中心拉取前端发布的虚拟目录及静态资源压缩包,下载静态资源压缩包并解压到网关设备的本地以对网关设备进行初始化;接收前端向网关设备发送的请求静态资源的第一访问请求,根据第一访问请求查找前端的虚拟目录,并返回前端的页面及静态文件内容给所述前端;及接收前端向初始化后的网关设备发送的请求动态资源的第二访问请求,根据第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
Description
本申请要求于2020年3月18日提交中国专利局、申请号为202010193478.6,发明名称为“基于应用程序接口网关的前后端分离方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及计算机网络领域,具体涉及一种基于应用程序接口网关的前后端分离方法、装置、网关设备及计算机可读存储介质。
目前,前后端单体架构的前端页面和后端服务放在同一个Java应用中,也就是前端静态页面以resource目录的形式打包在JAR包中。发明人意识到该方式维护较困难,前端项目有更改时,必须重新打包JAR包。此外,发明人还意识到前后端项目开发人员必须在同一代码库进行协作开发,前后端逻辑耦合在一起,使得前后端部署维护较困难,且版本难于管理。
发明内容
鉴于以上内容,有必要提出一种基于应用程序接口网关的前后端分离方法、装置、网关设备及计算机可读存储介质以解决前后端的开发成本消耗过大,前后端部署维护较困难及难以管理的问题。
本申请的第一方面提供一种基于应用程序接口网关的前后端分离方法,应用在网关设备中,所述方法包括:
从与所述网关设备通信连接的多租户配置中心获取网关设备前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;
接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;及
接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
申请的第二方面提供一种基于应用程序接口网关的前后端分离装置,所述装置包括:
初始化模块,用于从与所述网关设备通信连接的多租户配置中心获取所述网关设备的配置信息、前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;
第一访问模块,用于接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;及
第二访问模块,用于接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备 将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
本申请的第三方面提供一种网关设备,其中:所述网关设备包括处理器及存储器,所述处理器用于执行所述存储器中存储的计算机可读指令以实现以下步骤:
从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;
接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;
接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
本申请的第四方面提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机可读指令,其中,所述计算机可读指令被处理器执行时实现以下步骤:
从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;
接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;
接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
综上所述,本申请中,与所述多租户配置中心相连接的网关设备支持多租户访问所述PG数据库,并通过多租户配置中心获取前端的虚拟目录以及静态资源压缩包,如此,避免用户单独申请PG数据库,造成资源浪费及前后端的开发成本消耗过大的问题。此外,本申请中,所述网关设备可作为静态资源的服务器对静态资源压缩包的自动下载,解压,以及路由匹配,因此,不需要另外再购买及部署静态资源服务器,也不需要用户手动部署前端的静态资源代码,节省了手动部署静态资源的流程,解决了前后端部署维护困难及难以管理的问题。
图1是本申请一实施方式中基于应用程序接口网关的前后端分离方法的流程图。
图2是本申请一实施方式中基于应用程序接口网关的前后端分离方法的应用环境示意图。
图3是本申请一实施方式中基于应用程序接口网关的前后端分离装置的示意图。
图4是本申请一实施方式中网关设备的示意图。
为了能够更清楚地理解本申请的上述目的、特征和优点,下面结合附图和具体实施例对本申请进行详细描述。需要说明的是,在不冲突的情况下,本申请的实施例及实施例中的特征可以相互组合。
在下面的描述中阐述了很多具体细节以便于充分理解本申请,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
除非另有定义,本文所使用的所有的技术和科学术语与属于本申请的技术领域的技术人员通常理解的含义相同。本文中在本申请的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本申请。
优选地,本申请基于应用程序接口网关的前后端分离方法应用在一个或者多个电子设备中。所述电子设备是一种能够按照事先设定或存储的指令,自动进行数值计算和/或信息处理的设备,其硬件包括但不限于微处理器、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程门阵列(Field-Programmable Gate Array,FPGA)、数字处理器(Digital Signal Processor,DSP)、嵌入式设备等。
实施例一
图1是本申请一实施方式中基于应用程序接口网关的前后端分离方法的流程图。根据不同的需求,所述流程图中步骤的顺序可以改变,某些步骤可以省略。
参阅图1所示,所述基于应用程序接口网关的前后端分离方法具体包括以下步骤:
步骤S11,在网关设备1配置的PG数据库中存储前端2的虚拟目录以及静态资源压缩包,其中所述虚拟目录存储所述前端2的项目文件及所述项目文件的压缩文件。
请参考图2,所示为本申请一实施方式中基于应用程序接口网关的前后端分离方法的应用环境图。所述基于应用程序接口网关的前后端分离方法应用在所述网关设备1中。所述网关设备1通过网络与前端2、后端3及云平台4通信连接。本实施方式中,所述前端2为带有浏览器的设备,例如,所示前端2为笔记本电脑、平板电脑或智能手机等终端设备。所述后端3为服务器装置。所述云平台4为云服务器。
本实施方式中,在所述PG数据库中新增第一表格及第二表格,所述第一表格用于存储前端2的项目文件,所述第二表格用于存储项目的压缩文件。所述PG数据库设置在云平台4的PaaS服务层中。本实施方式中,通过网关设备1在云平台4的PaaS服务层的PG数据库中配置存储所述第一表格及第二表格的项目文件及项目文件的压缩文件。其中,所述项目文件包括项目标识号、文件名、文件路径、禁用/开启标示、创建时间标示、更新时间标示。所述项目文件的压缩文件包括文件标识号、文件名、文件类型、文件内容、文件大小、版本、对应的虚拟目录、禁用/开启标示、创建时间标示、更新时间标示。
步骤S12,从与所述网关设备通信连接的多租户配置中心获取所述网关设备的配置数据,从网关设备1配置管理的Restful APIs中确定一目标API,通过所述目标API对所述网关设备1的配置数据进行查询和修改,并将修改后的所述配置数据存储到所述PG数据库中。
本实施方式中,所述云平台4包括KONG-PORTAL-ADMIN服务功能。本实施方式中,通过管理控制台Portal上对网关设备1的配置数据进行配置管理,并通过所述云平台4的KONG-PORTAL-ADMIN服务的目标API对存储在第一表格及第二表格中的配置数据进行查询和修改,并将所述配置数据存储到云平台4的PG数据库中。在具体实施方式中,所述管理控制平台Portal提供管理界面,并通过所述管理界面对网关设备1进行配置管理。本实施方式中,所述网关设备1接收所述管理界面对所述网关设备1进行配置管理的操作。本实施方式中,所述管理控制台Portal对网关设备1进行配置管理的操作包括发布前端2的内容,管理前端2与后端3之间的入口流量的路由转发配置。本 实施方式中,所述前端2的静态资源压缩包的数据通过所述管理控制台Portal上传到PG数据库中进行存储。本实施方式中,通过提供网关设备1配置管理的Restful APIs,并通过Restful APIs对网关设备1的配置数据进行查询和修改,可以方便用户对网关设备1的配置数据进行修改。
步骤S13,从与所述网关设备1通信连接的多租户配置中心获取前端2发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备1的本地以对所述网关设备1进行初始化。
本实施方式中,通过Go语言开发并构建多租户配置中心,并将所述多租户配置中心与所述网关设备1连接。本实施方式中,构建的所述多租户配置中心能够基于多租户对网关设备1的配置数据进行配置查询和存储。本实施方式中,与所述多租户配置中心相连接的网关设备1支持多租户访问所述PG数据库,并通过多租户配置中心获取前端2的虚拟目录以及静态资源压缩包,如此,避免用户单独申请PG数据库,造成资源浪费。
本实施方式中,所述网关设备1从与所述网关设备1通信连接的多租户配置中心获取所述静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备1的本地,实现了静态资源压缩包的自动下载、解压,避免部署额外的静态资源服务器用来对静态资源压缩包的自动下载、解压,节省了服务器资源及手动部署流程。
本实施方式中,所述网关设备1从与所述网关设备1通信连接的多租户配置中心获取所述网关设备1的配置数据、前端2发布的虚拟目录及静态资源压缩包包括:通过云平台4的KONG-PORTAL-ADMIN服务功能在数据库中插入用户对所述虚拟目录或前端静态资源压缩包进行发布修改的通知事件;所述网关设备1监测所述通知事件并在监测出所述通知事件时从所述多租户配置中心中获取最新的虚拟目录及静态资源压缩包,并更新到本地。本实施方式中,所述网关设备1的配置数据包括第一访问请求的路径及虚拟目录的路径之间的路由关系。
步骤S14,接收所述前端2的浏览器向初始化后的所述网关设备1发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端2的虚拟目录的路径,并在所述第一访问请求的路径与所述前端2的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端2的虚拟目录,根据所述第一访问请求查找所述前端2的虚拟目录,并返回所述前端2的页面及静态文件内容给所述前端2的浏览器。
本实施方式中,所述浏览器使用HTTP协议发送所述第一访问请求以请求静态资源。所述网关设备1根据所述第一访问请求的路径匹配对应的前端2的虚拟目录的路径。当所述第一访问请求的路径与前端2的虚拟目录的路径相匹配时将所述第一访问请求转发到所述网关设备1的5000端口的内部静态站点对应的虚拟目录,从所述虚拟目录中取出所述前端2的页面及静态文件,并将取出的所述前端2的页面及静态文件内容返回给所述前端2的浏览器。本实施方式中,当所述第一访问请求的路径与前端2的虚拟目录的路径不相匹配时,所述网关设备1返回错误信息给所述前端2。本实施方式中,所述前端2收到所述网关设备1发送的错误信息后重新向所述网关设备1发送请求静态资源的第一访问请求。本实施方式中,所述前端2的浏览器接收到所述网关设备1返回的页面及静态文件内容之后经过浏览器渲染解析后,在所述浏览器上得到渲染的效果。本实施方式中,所述网关设备1可作为静态资源的服务器对静态资源压缩包的自动下载,解压,以及路由匹配,因此,不需要另外再购买及部署静态资源服务器,也不需要用户手动部署前端2的静态资源代码,节省了手动部署静态资源的流程。
具体实施方式中,在所述网关设备1的Nginx配置模板中,通过5000端口监听从5000端口进来的访问流量;对所述5000端口进来的第一访问请求进行拦截,针对第一访问请求的路径匹配对应的虚拟目录路径,将所述第一访问请求发送到对应的前端2的虚拟目录,根据所述第一访问请求查找所述前端2的虚拟目录,并返回所述前端2的页面及静态文件内容给所述前端2。
本实施方式中,所述网关设备1的配置数据包括前端2的灰度策略,所述方法还包括:通过5000端口监听从5000端口进来的第一访问请求;根据所述灰度策略,对所述5000端口进来的第一访问请求进行拦截并判断所述第一访问请求是否满足所述灰度策略的要求;当所述第一访问请求满足所述灰度策略的要求时,针对所述第一访问请求的路径匹配对应的虚拟目录路径,将所述第一访问请求发送到对应的虚拟目录,根据所述第一访问请求查找所述虚拟目录,并返回所述前端2的页面及静态文件内容给所述前端2的浏览器。本实施方式中,所述灰度策略是指针对不同的前端2设定不同的访问权限。
步骤S15,接收所述前端2向初始化后的所述网关设备1发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备1将调用的后端API的请求转发到后端3的微服务以获取所述动态资源,并通过所述网关设备1将所述动态资源返回给所述前端2。
本实施方式中,所述前端2的浏览器使用HTTP协议发送所述第二访问请求以请求动态资源。所述网关设备1根据设置在所述网关设备1中的后端3的微服务请求的转发路由触发调用后端API的请求,通过所述网关设备1将调用的后端API的请求转发到后端3的微服务以获取所述动态资源,并通过所述网关设备1将所述动态资源返回给所述前端2的浏览器。如此,本案通过网关设备1实现了前端2与后端3完全分离的架构,前端人员只关注前端代码开发并通过网关设备1进行前端页面的发布与管理,后端人员只关注后端3的微服务代码的开发,及在网关设备1中配置相应的路由,并对所述后端API请求进行转发。
本实施方式中,所述方法还包括:判断所述前端2的浏览器发送的第二访问请求是否是请求访问所述前端的超链接请求,将所述第二访问请求分成超链接请求和非超链接请求,其中,超链接请求是指http请求是由一个与http请求对应的html界面超链接而产生,非超链接请求是指不与任何html界面存在超链接关系;如果确定所述第二访问请求为超链接请求,则对超链接请求的地址进行重定向,并将重定向的地址返回给前端2的浏览器以使浏览器生成新的访问请求;接收前端2的浏览器发送的新的访问请求,并将新的访问请求通转发至对应的后端3的微服务;及接收所述后端3返回的与新的访问请求对应的访问响应,并通过所述将访问响应返回至所述前端2的浏览器。
本实施方式中,所述超级链接在本质上属于一个网页的一部分,它是一种允许其他网页或站点之间进行连接的元素,其必然存在地址跳转的问题。如果网关设备1接收到前端2的浏览器发送的第二访问请求之后,并判断所述第二访问请求为超链接请求时,所述网关设备1不直接将所述第二访问请求进行转发至其对应的后端3的微服务获取对应的资源,而是对所述第二访问请求的请求地址进行重定向,地址重定向后的访问请求为网关设备1直接转发的访问请求。
本实施方式中,所述网关设备1在判断http请求是否为超链接请求之前,还将所述http请求与网关设备1预先配置的API进行匹配,如果所述http请求与预先配置的API匹配成功,例如,可以是基于http请求的uri与预先配置的API进行匹配,那么网关设备1将所述http请求转发到匹配API所指向的后端3的微服务的地址,以获取后端3的微服务返回的资源。本实施方式中,当所述网关设备1确定所述http请求与任何预先配置的API都不能匹配成功,则对http请求是否为超链接请求进行判断;如果确定所述http请求为非超链接请求时将所述http请求判定为请求失败,并无法获取后端微服务返回的资源;如果确定所述http请求为超链接请求,则对所述超链接请求的地址进行重定向。
本实施方式中,与所述多租户配置中心相连接的网关设备1支持多租户访问所述PG数据库,并通过多租户配置中心获取前端2的虚拟目录以及静态资源压缩包,如此,避免用户单独申请PG数据库,造成资源浪费。此外,本案中,所述网关设备1可作为静态资源的服务器对静态资源压缩包的自动下载,解压,以及路由匹配,因此,不需要另 外再购买及部署静态资源服务器,也不需要用户手动部署前端2的静态资源代码,节省了手动部署静态资源的流程。
实施例二
图3为本申请一实施方式中基于应用程序接口网关的前后端分离装置40的示意图。
在一些实施例中,所述基于应用程序接口网关的前后端分离装置40运行于网关设备1中。所述基于应用程序接口网关的前后端分离装置40可以包括多个由程序代码段所组成的功能模块。所述基于应用程序接口网关的前后端分离装置40中的各个程序段的程序代码可以存储于存储器中,并由至少一个处理器所执行,以执行前后端分离的功能。
本实施例中,所述基于应用程序接口网关的前后端分离装置40根据其所执行的功能,可以被划分为多个功能模块。参阅图3所示,所述基于应用程序接口网关的前后端分离装置40可以包括预存储模块401、配置模块402、初始化模块403、第一访问模块404及第二访问模块405。本申请所称的模块是指一种能够被至少一个处理器所执行并且能够完成固定功能的一系列计算机程序段,其存储在存储器中。在一些实施例中,关于各模块的功能将在后续的实施例中详述。
所述预存储模块401在网关设备1配置的PG数据库中存储前端2的虚拟目录以及静态资源压缩包,其中所述虚拟目录存储所述前端2的项目文件及所述项目文件的压缩文件。
本实施方式中,所述预存储模块401在所述PG数据库中新增第一表格及第二表格,所述第一表格用于存储前端2的项目文件,所述第二表格用于存储项目的压缩文件。所述PG数据库设置在云平台4的PaaS服务层中。本实施方式中,所述预存储模块401通过网关设备1在云平台4的PaaS服务层的PG数据库中配置存储所述第一表格及第二表格的项目文件及项目文件的压缩文件。其中,所述项目文件包括项目标识号、文件名、文件路径、禁用/开启标示、创建时间标示、更新时间标示。所述项目文件的压缩文件包括文件标识号、文件名、文件类型、文件内容、文件大小、版本、对应的虚拟目录、禁用/开启标示、创建时间标示、更新时间标示。
所述配置模块402从与所述网关设备通信连接的多租户配置中心获取所述网关设备的配置数据,从网关设备1配置管理的Restful APIs中确定一目标API,通过所述目标API对所述网关设备1的配置数据进行查询和修改,并将修改后的所述配置数据存储到所述PG数据库中。
本实施方式中,所述云平台4包括KONG-PORTAL-ADMIN服务功能。本实施方式中,所述配置模块402通过管理控制台Portal上对网关设备1的配置数据进行配置管理,并通过所述云平台4的KONG-PORTAL-ADMIN服务的目标API对存储在第一表格及第二表格中的配置数据进行查询和修改,并将所述配置数据存储到云平台4的PG数据库中。在具体实施方式中,所述管理控制平台Portal提供管理界面,所述配置模块402通过所述管理界面对网关设备1进行配置管理。本实施方式中,所述网关设备1接收所述管理界面对所述网关设备1进行配置管理的操作。本实施方式中,所述管理控制台Portal对网关设备1进行配置管理的操作包括发布前端2的内容,管理前端2与后端3之间的入口流量的路由转发配置。本实施方式中,所述前端2的静态资源压缩包的数据通过所述管理控制台Portal上传到PG数据库中进行存储。本实施方式中,通过提供网关设备1配置管理的Restful APIs,并通过Restful APIs对网关设备1的配置数据进行查询和修改,可以方便用户对网关设备1的配置数据进行修改。
所述初始化模块403从与所述网关设备1通信连接的多租户配置中心获取所述网关设备1的配置数据、前端2发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备1的本地以对所述网关设备1进行初始化。
本实施方式中,所述初始化模块403通过Go语言开发并构建多租户配置中心,并将所述多租户配置中心与所述网关设备1连接。本实施方式中,构建的所述多租户配置中 心能够基于多租户对网关设备1的配置数据进行配置查询和存储。本实施方式中,与所述多租户配置中心相连接的网关设备1支持多租户访问所述PG数据库,并通过多租户配置中心获取前端2的虚拟目录以及静态资源压缩包,如此,避免用户单独申请PG数据库,造成资源浪费。
本实施方式中,所述初始化模块403从与所述网关设备1通信连接的多租户配置中心获取所述静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备1的本地,实现了静态资源压缩包的自动下载、解压,避免部署额外的静态资源服务器用来对静态资源压缩包的自动下载、解压,节省了服务器资源及手动部署流程。
本实施方式中,所述初始化模块403从与所述网关设备1通信连接的多租户配置中心获取前端2发布的虚拟目录及静态资源压缩包包括:通过云平台4的KONG-PORTAL-ADMIN服务功能在数据库中插入用户对所述虚拟目录或前端静态资源压缩包进行发布修改的通知事件;所述网关设备1监测所述通知事件并在监测出所述通知事件时从所述多租户配置中心中获取最新的虚拟目录及静态资源压缩包,并更新到本地。本实施方式中,所述网关设备1的配置数据包括第一访问请求的路径及虚拟目录的路径之间的路由关系。
所述第一访问模块404接收所述前端2的浏览器向初始化后的所述网关设备1发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端2的虚拟目录的路径,并在所述第一访问请求的路径与所述前端2的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端2的虚拟目录,根据所述第一访问请求查找所述前端2的虚拟目录,并返回所述前端2的页面及静态文件内容给所述前端2的浏览器。
本实施方式中,所述浏览器使用HTTP协议发送所述第一访问请求以请求静态资源。所述第一访问模块404根据所述第一访问请求的路径匹配对应的前端2的虚拟目录的路径。当所述第一访问请求的路径与前端2的虚拟目录的路径相匹配时将所述第一访问请求转发到所述网关设备1的5000端口的内部静态站点对应的虚拟目录,从所述虚拟目录中取出所述前端2的页面及静态文件,并将取出的所述前端2的页面及静态文件内容返回给所述前端2的浏览器。本实施方式中,当所述第一访问请求的路径与前端2的虚拟目录的路径不相匹配时,所述第一访问模块404返回错误信息给所述前端2。本实施方式中,所述前端2收到所述网关设备1发送的错误信息后重新向所述网关设备1发送请求静态资源的第一访问请求。本实施方式中,所述前端2的浏览器接收到所述第一访问模块404返回的页面及静态文件内容之后经过浏览器渲染解析后,在所述浏览器上得到渲染的效果。本实施方式中,所述网关设备1可作为静态资源的服务器对静态资源压缩包的自动下载,解压,以及路由匹配,因此,不需要另外再购买及部署静态资源服务器,也不需要用户手动部署前端2的静态资源代码,节省了手动部署静态资源的流程。
具体实施方式中,所述第一访问模块404在所述网关设备1的Nginx配置模板中,通过5000端口监听从5000端口进来的第一访问请求;对所述5000端口进来的第一访问请求进行拦截,针对第一访问请求的路径匹配对应的虚拟目录路径,将所述第一访问请求发送到对应的前端2的虚拟目录,根据所述第一访问请求查找所述前端2的虚拟目录,并返回所述前端2的页面及静态文件内容给所述前端2。
本实施方式中,所述网关设备1的配置数据包括前端2的灰度策略,所述第一访问模块404还包括:通过5000端口监听从5000端口进来的访问流量;根据所述灰度策略,对所述5000端口进来的第一访问请求进行拦截并判断所述第一访问请求是否满足所述灰度策略的要求;当所述第一访问请求满足所述灰度策略的要求时针对所述第一访问请求的路径匹配对应的虚拟目录路径,将所述第一访问请求发送到对应的虚拟目录,根据所述第一访问请求查找所述虚拟目录,并返回所述前端2的页面及静态文件内容给所述前端2的浏览器。本实施方式中,所述灰度策略是指针对不同的前端2设定不同的访问权限。
所述第二访问模块405接收所述前端2向初始化后的所述网关设备1发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备1将调用的后端API的请求转发到后端3的微服务以获取所述动态资源,并通过所述网关设备1将所述动态资源返回给所述前端2。
本实施方式中,所述前端2的浏览器使用HTTP协议发送所述第二访问请求以请求动态资源。所述第二访问模块405根据设置在所述网关设备1中的后端3的微服务请求的转发路由触发调用后端API的请求,通过所述网关设备1将调用的后端API的请求转发到后端3的微服务以获取所述动态资源,并通过所述网关设备1将所述动态资源返回给所述前端2的浏览器。如此,本案通过网关设备1实现了前端2与后端3完全分离的架构,前端人员只关注前端代码开发并通过网关设备1进行前端页面的发布与管理,后端人员只关注后端3的微服务代码的开发,及在网关设备1中配置相应的路由,并对所述后端API请求进行转发。
本实施方式中,所述第二访问模块405还用于:判断所述前端2的浏览器发送的第二访问请求是否是请求访问所述前端的超链接请求,将所述第二访问请求分成超链接请求和非超链接请求,其中,超链接请求是指http请求是由一个与http请求对应的html界面超链接而产生,非超链接请求是指不与任何html界面存在超链接关系;如果确定所述第二访问请求为超链接请求,则对超链接请求的地址进行重定向,并将重定向的地址返回给前端2的浏览器以使浏览器生成新的访问请求;接收前端2的浏览器发送的新的访问请求,并将新的访问请求通过所述网关设备1转发至对应的后端3的微服务;及接收所述后端3返回的与新的访问请求对应的访问响应,并通过所述网关设备1将访问响应返回至所述前端2的浏览器。
本实施方式中,所述超级链接在本质上属于一个网页的一部分,它是一种允许其他网页或站点之间进行连接的元素,其必然存在地址跳转的问题。如果网关设备1接收到前端2的浏览器发送的第二访问请求之后,并判断所述第二访问请求为超链接请求时,所述网关设备1不直接将所述第二访问请求进行转发至其对应的后端3的微服务获取对应的资源,而是对所述第二访问请求的请求地址进行重定向,地址重定向后的访问请求为网关设备1直接转发的访问请求。
本实施方式中,所述第二访问模块405在判断http请求是否为超链接请求之前,还将所述http请求与网关设备1预先配置的API进行匹配,如果所述http请求与预先配置的API匹配成功,例如,可以是基于http请求的uri与预先配置的API进行匹配,那么所述第二访问模块405将所述http请求转发到匹配API所指向的后端3的微服务的地址,以获取后端3的微服务返回的资源。本实施方式中,当所述第二访问模块405确定所述http请求与任何预先配置的API都不能匹配成功,则对http请求是否为超链接请求进行判断;如果确定所述http请求为非超链接请求时将所述http请求判定为请求失败,并无法获取后端微服务返回的资源;如果确定所述http请求为超链接请求,则对所述超链接请求的地址进行重定向。
本实施方式中,与所述多租户配置中心相连接的网关设备1支持多租户访问所述PG数据库,并通过多租户配置中心获取前端2的虚拟目录以及静态资源压缩包,如此,避免用户单独申请PG数据库,造成资源浪费。此外,本案中,所述网关设备1可作为静态资源的服务器对静态资源压缩包的自动下载,解压,以及路由匹配,因此,不需要另外再购买及部署静态资源服务器,也不需要用户手动部署前端2的静态资源代码,节省了手动部署静态资源的流程。
实施例三
图4为本申请一实施方式中网关设备1的示意图。
所述网关设备1包括存储器20、处理器30以及存储在所述存储器20中并可在所述处理器30上运行的计算机程序40。所述处理器30执行所述计算机程序40时实现上述 基于应用程序接口网关的前后端分离方法实施例中的步骤,例如图1所示的步骤S11~S15。或者,所述处理器30执行所述计算机程序40时实现上述基于应用程序接口网关的前后端分离装置实施例中各模块/单元的功能,例如图3中的模块401~405。
示例性的,所述计算机程序40可以被分割成一个或多个模块/单元,所述一个或者多个模块/单元被存储在所述存储器20中,并由所述处理器30执行,以完成本申请。所述一个或多个模块/单元可以是能够完成特定功能的一系列计算机可读指令段,所述指令段用于描述所述计算机程序40在所述网关设备1中的执行过程。例如,所述计算机程序40可以被分割成图3中的预存储模块401、配置模块402、初始化模块403、第一访问模块404及第二访问模块405,各模块的具体功能参见实施例二。
本实施方式中,所述网关设备1可以是服务器。本领域技术人员可以理解,所述示意图仅仅是网关设备1的示例,并不构成对网关设备1的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如所述网关设备1还可以包括输入输出设备、网络接入设备、总线等。
所称处理器30可以是中央处理模块(Central Processing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者所述处理器30也可以是任何常规的处理器等,所述处理器30是所述网关设备1的控制中心,利用各种接口和线路连接整个网关设备1的各个部分。
所述存储器20可用于存储所述计算机程序40和/或模块/单元,所述处理器30通过运行或执行存储在所述存储器20内的计算机程序和/或模块/单元,以及调用存储在存储器20内的数据,实现所述网关设备1的各种功能。所述存储器20可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据网关设备1的使用所创建的数据(比如音频数据)等。此外,存储器20可以包括非易失性存储器和易失性存储器,例如硬盘、内存、插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)、至少一个磁盘存储器件、闪存器件、或其他存储器件。所述计算机可读存储介质可以是非易失性,也可以是易失性的。
所述网关设备1集成的模块/单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,也可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,所述计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器等。
在本申请所提供的几个实施例中,应该理解到,所揭露的网关设备和方法,可以通过其它的方式实现。例如,以上所描述的网关设备实施例仅仅是示意性的,例如,所述模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
另外,在本申请各个实施例中的各功能模块可以集成在相同处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在相同模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用硬件加软件功能模块的形式实现。
对于本领域技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其他的具体形式实现本申请。因此,无论从哪一点来看,均应将实施例看作是示范性的,而且是非限制性的,本申请的范围由 所附权利要求而不是上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化涵括在本申请内。不应将权利要求中的任何附图标记视为限制所涉及的权利要求。此外,显然“包括”一词不排除其他模块或步骤,单数不排除复数。本申请中陈述的多个模块或网关设备也可以由同一个模块或网关设备通过软件或者硬件来实现。第一,第二等词语用来表示名称,而并不表示任何特定的顺序。
最后应说明的是,以上实施例仅用以说明本申请的技术方案而非限制,尽管参照较佳实施例对本申请进行了详细说明,本领域的普通技术人员应当理解,可以对本申请的技术方案进行修改或等同替换,而不脱离本申请技术方案的精神和范围。
Claims (20)
- 一种基于应用程序接口网关的前后端分离方法,应用在网关设备中,其中,所述方法包括:从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
- 如权利要求1所述的基于应用程序接口网关的前后端分离方法,其中,在从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包之前,所述方法还包括:在所述网关设备配置的PG数据库中存储前端的虚拟目录以及静态资源压缩包,其中所述虚拟目录存储所述前端的项目文件及所述项目文件的压缩文件。
- 如权利要求2所述的基于应用程序接口网关的前后端分离方法,其中,在所述网关设备配置的PG数据库中存储前端的虚拟目录以及静态资源压缩包之后,所述方法还包括:从与所述网关设备通信连接的多租户配置中心获取所述网关设备的配置数据,从所述网关设备配置管理的Restful APIs中确定一目标API,通过所述目标API对所述网关设备的配置数据进行查询和修改,并将修改后的所述配置数据存储到所述PG数据库中。
- 如权利要求3所述的基于应用程序接口网关的前后端分离方法,其中,在所述网关设备配置的PG数据库中存储前端的虚拟目录以及静态资源压缩包之后,所述方法还包括:接收由管理控制平台Portal提供的管理界面对所述网关设备进行配置管理的操作,其中,所述管理控制台Portal对所述网关设备进行配置管理的操作包括发布所述前端的内容,管理所述前端与所述后端之间的入口流量的路由转发配置。
- 如权利要求1所述的基于应用程序接口网关的前后端分离方法,其中,所述从与所述网关设备通信连接的多租户配置中心获取网关设备前端发布的虚拟目录及静态资源压缩包,包括:通过云平台的KONG-PORTAL-ADMIN服务功能在数据库中插入用户对所述虚拟目录或所述前端静态资源压缩包进行发布修改的通知事件;监测所述通知事件并在监测出所述通知事件时从所述多租户配置中心中获取最新的虚拟目录及静态资源压缩包,并更新到本地。
- 如权利要求3所述的基于应用程序接口网关的前后端分离方法,所述网关设备的配置数据包括所述前端的灰度策略,其中,所述方法还包括:通过5000端口监听从5000端口进来的第一访问请求;根据所述灰度策略,对所述5000端口进来的第一访问请求进行拦截并判断所述第一访问请求是否满足所述灰度策略的要求;当所述第一访问请求满足所述灰度策略的要求时,针对所述第一访问请求的路径匹配对应的虚拟目录路径,将所述第一访问请求发送 到对应的虚拟目录,根据所述第一访问请求查找所述虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器。
- 如权利要求1所述的基于应用程序接口网关的前后端分离方法,其中,所述方法还包括:判断所述前端的浏览器发送的第二访问请求是否是请求访问所述前端的超链接请求,将所述第二访问请求分成超链接请求和非超链接请求,其中,所述超链接请求是指http请求是由一个与http请求对应的html界面超链接而产生,非超链接请求不与任何html界面存在超链接关系;如果确定所述第二访问请求为超链接请求,则对超链接请求的地址进行重定向,并将重定向的地址返回给前端的浏览器以使浏览器生成新的访问请求;接收所述前端的浏览器发送的新的访问请求,并将新的访问请求转发至对应的后端的微服务;接收所述后端返回的与新的访问请求对应的访问响应,并将访问响应返回至所述前端的浏览器。
- 如权利要求1所述的基于应用程序接口网关的前后端分离方法,其中,所述接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求之后,还包括:当所述第一访问请求的路径与所述前端的虚拟目录的路径不相匹配时,返回错误信息给所述前端。
- 一种基于应用程序接口网关的前后端分离装置,其中,所述装置包括:初始化模块,用于从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;第一访问模块,用于接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;及第二访问模块,用于接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
- 一种网关设备,其中:所述网关设备包括处理器及存储器,所述处理器用于执行所述存储器中存储的计算机可读指令以实现以下步骤:从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
- 如权利要求10所述的网关设备,其中,所述处理器执行所述计算机可读指令以实现从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包之前,还包括:在所述网关设备配置的PG数据库中存储前端的虚拟目录以及静态资源压缩包,其中所述虚拟目录存储所述前端的项目文件及所述项目文件的压缩文件。
- 如权利要求11所述的网关设备,其中,所述处理器执行所述计算机可读指令以实现在所述网关设备配置的PG数据库中存储前端的虚拟目录以及静态资源压缩包之后,还包括:从与所述网关设备通信连接的多租户配置中心获取所述网关设备的配置数据,从所述网关设备配置管理的Restful APIs中确定一目标API,通过所述目标API对所述网关设备的配置数据进行查询和修改,并将修改后的所述配置数据存储到所述PG数据库中。
- 如权利要求12所述的网关设备,其中,所述处理器执行所述计算机可读指令以实现所述网关设备配置的PG数据库中存储前端的虚拟目录以及静态资源压缩包之后,还包括:接收由管理控制平台Portal提供的管理界面对所述网关设备进行配置管理的操作,其中,所述管理控制台Portal对所述网关设备进行配置管理的操作包括发布所述前端的内容,管理所述前端与所述后端之间的入口流量的路由转发配置。
- 如权利要求10所述的网关设备,其中,所述处理器执行所述计算机可读指令以实现从与所述网关设备通信连接的多租户配置中心获取网关设备前端发布的虚拟目录及静态资源压缩包,包括:通过云平台的KONG-PORTAL-ADMIN服务功能在数据库中插入用户对所述虚拟目录或所述前端静态资源压缩包进行发布修改的通知事件;监测所述通知事件并在监测出所述通知事件时从所述多租户配置中心中获取最新的虚拟目录及静态资源压缩包,并更新到本地。
- 如权利要求12所述的网关设备,所述网关设备的配置数据包括所述前端的灰度策略,其中,所述处理器执行所述计算机可读指令还用以实现以下步骤:通过5000端口监听从5000端口进来的第一访问请求;根据所述灰度策略,对所述5000端口进来的第一访问请求进行拦截并判断所述第一访问请求是否满足所述灰度策略的要求;当所述第一访问请求满足所述灰度策略的要求时,针对所述第一访问请求的路径匹配对应的虚拟目录路径,将所述第一访问请求发送到对应的虚拟目录,根据所述第一访问请求查找所述虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器。
- 如权利要求10所述的网关设备,其中,所述处理器执行所述计算机可读指令还用以实现以下步骤:判断所述前端的浏览器发送的第二访问请求是否是请求访问所述前端的超链接请求,将所述第二访问请求分成超链接请求和非超链接请求,其中,所述超链接请求是指http请求是由一个与http请求对应的html界面超链接而产生,非超链接请求不与任何html界面存在超链接关系;如果确定所述第二访问请求为超链接请求,则对超链接请求的地址进行重定向,并将重定向的地址返回给前端的浏览器以使浏览器生成新的访问请求;接收所述前端的浏览器发送的新的访问请求,并将新的访问请求转发至对应的后端的微服务;接收所述后端返回的与新的访问请求对应的访问响应,并将访问响应返回至所述前端的浏览器。
- 如权利要求10所述的网关设备,其中,所述处理器执行所述计算机可读指令以实现所述接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问 请求之后,还包括:当所述第一访问请求的路径与所述前端的虚拟目录的路径不相匹配时,返回错误信息给所述前端。
- 一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机可读指令,其中,所述计算机可读指令被处理器执行时实现以下步骤:从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包,下载所述静态资源压缩包并解压到所述网关设备的本地以对所述网关设备进行初始化;接收所述前端的浏览器向初始化后的所述网关设备发送的请求静态资源的第一访问请求,根据所述第一访问请求的路径匹配所述前端的虚拟目录的路径,并在所述第一访问请求的路径与所述前端的虚拟目录的路径相匹配时将所述第一访问请求发送到所述前端的虚拟目录,根据所述第一访问请求查找所述前端的虚拟目录,并返回所述前端的页面及静态文件内容给所述前端的浏览器;接收所述前端向初始化后的所述网关设备发送的请求动态资源的第二访问请求,根据所述第二访问请求触发调用后端API的请求,通过所述网关设备将调用的后端API的请求转发到后端的微服务以获取所述动态资源,并通过所述网关设备将所述动态资源返回给所述前端。
- 如权利要求18所述的计算机可读存储介质,其中,所述计算机可读指令被所述处理器执行以实现从与所述网关设备通信连接的多租户配置中心获取前端发布的虚拟目录及静态资源压缩包之前,还包括:在所述网关设备配置的PG数据库中存储前端的虚拟目录以及静态资源压缩包,其中所述虚拟目录存储所述前端的项目文件及所述项目文件的压缩文件。
- 如权利要求18所述的计算机可读存储介质,其中,所述计算机可读指令被所述处理器执行以实现从与所述网关设备通信连接的多租户配置中心获取网关设备前端发布的虚拟目录及静态资源压缩包,具体包括:通过云平台的KONG-PORTAL-ADMIN服务功能在数据库中插入用户对所述虚拟目录或所述前端静态资源压缩包进行发布修改的通知事件;监测所述通知事件并在监测出所述通知事件时从所述多租户配置中心中获取最新的虚拟目录及静态资源压缩包,并更新到本地。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010193478.6 | 2020-03-18 | ||
| CN202010193478.6A CN111580854A (zh) | 2020-03-18 | 2020-03-18 | 基于应用程序接口网关的前后端分离方法及相关设备 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2021184824A1 true WO2021184824A1 (zh) | 2021-09-23 |
Family
ID=72112970
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2020/132351 Ceased WO2021184824A1 (zh) | 2020-03-18 | 2020-11-27 | 基于应用程序接口网关的前后端分离方法及相关设备 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN111580854A (zh) |
| WO (1) | WO2021184824A1 (zh) |
Cited By (9)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114024846A (zh) * | 2021-11-18 | 2022-02-08 | 上海宝创网络科技有限公司 | 一种生成网关功能的方法及设备 |
| CN114048413A (zh) * | 2021-10-18 | 2022-02-15 | 深圳市宏电技术股份有限公司 | 一种web管理方法及装置 |
| CN114510254A (zh) * | 2022-03-10 | 2022-05-17 | 广州博冠信息科技有限公司 | 资源更新方法、装置、电子设备和存储介质 |
| CN114615251A (zh) * | 2022-03-24 | 2022-06-10 | 中电科思仪科技股份有限公司 | 一种实现采算分离的信号测试仪器云控制系统及方法 |
| CN114741631A (zh) * | 2022-03-02 | 2022-07-12 | 中广核智能科技(深圳)有限责任公司 | 动态网页访问速度提升方法、系统、存储介质及终端 |
| CN115567581A (zh) * | 2022-10-09 | 2023-01-03 | 深圳供电局有限公司 | 基于微服务的分离式链路数据的管控方法及装置 |
| CN116595285A (zh) * | 2023-07-19 | 2023-08-15 | 深圳复临科技有限公司 | 一种路由生成方法、装置、计算机设备及存储介质 |
| CN119938176A (zh) * | 2024-11-28 | 2025-05-06 | 天翼云科技有限公司 | 后端数据的调度方法、装置、设备、存储介质及程序产品 |
| CN120389993A (zh) * | 2025-06-27 | 2025-07-29 | 苏州元脑智能科技有限公司 | 电子设备以及请求处理方法 |
Families Citing this family (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111580854A (zh) * | 2020-03-18 | 2020-08-25 | 平安科技(深圳)有限公司 | 基于应用程序接口网关的前后端分离方法及相关设备 |
| CN114301890B (zh) * | 2020-09-22 | 2023-09-05 | 中国移动通信集团安徽有限公司 | Web访问请求的处理方法及装置 |
| CN112487339B (zh) * | 2020-12-11 | 2023-05-26 | 杭州安恒信息技术股份有限公司 | 一种Web页面请求的响应方法、装置、设备及存储介质 |
| CN112667204B (zh) * | 2020-12-15 | 2024-01-23 | 南方电网数字平台科技(广东)有限公司 | 微服务应用的数据处理方法、装置和计算机设备 |
| CN112559180B (zh) * | 2020-12-16 | 2024-03-26 | 微医云(杭州)控股有限公司 | 资源处理方法、装置、电子设备及存储介质 |
| CN114697065B (zh) * | 2020-12-31 | 2024-04-30 | 中国联合网络通信集团有限公司 | 安全认证方法和安全认证装置 |
| CN113220273B (zh) * | 2021-05-20 | 2024-06-04 | 南方电网数字电网研究院有限公司 | 微前端应用资源处理方法、装置、设备和介质 |
| CN113420237B (zh) * | 2021-05-21 | 2025-11-18 | 北京沃东天骏信息技术有限公司 | 一种信息处理方法及装置、存储介质 |
| CN113467860B (zh) * | 2021-06-22 | 2024-01-19 | 上海星融汽车科技有限公司 | 一种程序源代码的业务逻辑执行方法及装置 |
| CN115758015A (zh) * | 2022-10-09 | 2023-03-07 | 深圳市酷开网络科技股份有限公司 | 网页用户界面的开发调试方法及相关装置 |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20050021688A1 (en) * | 2003-02-25 | 2005-01-27 | David Felts | System and method for domain configuration |
| CN109710878A (zh) * | 2018-12-28 | 2019-05-03 | 北京百佑科技有限公司 | 数据交互方法及服务器 |
| CN110673839A (zh) * | 2019-09-10 | 2020-01-10 | 口碑(上海)信息技术有限公司 | 分布式工具配置化构建生成方法及系统 |
| CN111580854A (zh) * | 2020-03-18 | 2020-08-25 | 平安科技(深圳)有限公司 | 基于应用程序接口网关的前后端分离方法及相关设备 |
Family Cites Families (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US10484382B2 (en) * | 2016-08-31 | 2019-11-19 | Oracle International Corporation | Data management for a multi-tenant identity cloud service |
| CN108989362A (zh) * | 2017-05-31 | 2018-12-11 | 北京京东尚科信息技术有限公司 | 一种静态资源的处理方法和装置 |
| CN107645508A (zh) * | 2017-10-16 | 2018-01-30 | 深圳市买买提乐购金融服务有限公司 | 一种数据处理系统、方法、客户端及服务器 |
| CN109635217A (zh) * | 2018-12-14 | 2019-04-16 | 平安普惠企业管理有限公司 | App的h5页面加载方法、装置、计算机设备和存储介质 |
| CN110708368A (zh) * | 2019-09-25 | 2020-01-17 | 北京计算机技术及应用研究所 | 一种基于路由分发的微前端系统和方法 |
-
2020
- 2020-03-18 CN CN202010193478.6A patent/CN111580854A/zh active Pending
- 2020-11-27 WO PCT/CN2020/132351 patent/WO2021184824A1/zh not_active Ceased
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20050021688A1 (en) * | 2003-02-25 | 2005-01-27 | David Felts | System and method for domain configuration |
| CN109710878A (zh) * | 2018-12-28 | 2019-05-03 | 北京百佑科技有限公司 | 数据交互方法及服务器 |
| CN110673839A (zh) * | 2019-09-10 | 2020-01-10 | 口碑(上海)信息技术有限公司 | 分布式工具配置化构建生成方法及系统 |
| CN111580854A (zh) * | 2020-03-18 | 2020-08-25 | 平安科技(深圳)有限公司 | 基于应用程序接口网关的前后端分离方法及相关设备 |
Cited By (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114048413A (zh) * | 2021-10-18 | 2022-02-15 | 深圳市宏电技术股份有限公司 | 一种web管理方法及装置 |
| CN114024846A (zh) * | 2021-11-18 | 2022-02-08 | 上海宝创网络科技有限公司 | 一种生成网关功能的方法及设备 |
| CN114741631A (zh) * | 2022-03-02 | 2022-07-12 | 中广核智能科技(深圳)有限责任公司 | 动态网页访问速度提升方法、系统、存储介质及终端 |
| CN114510254A (zh) * | 2022-03-10 | 2022-05-17 | 广州博冠信息科技有限公司 | 资源更新方法、装置、电子设备和存储介质 |
| CN114615251A (zh) * | 2022-03-24 | 2022-06-10 | 中电科思仪科技股份有限公司 | 一种实现采算分离的信号测试仪器云控制系统及方法 |
| CN114615251B (zh) * | 2022-03-24 | 2024-05-03 | 中电科思仪科技股份有限公司 | 一种实现采算分离的信号测试仪器云控制系统及方法 |
| CN115567581A (zh) * | 2022-10-09 | 2023-01-03 | 深圳供电局有限公司 | 基于微服务的分离式链路数据的管控方法及装置 |
| CN116595285A (zh) * | 2023-07-19 | 2023-08-15 | 深圳复临科技有限公司 | 一种路由生成方法、装置、计算机设备及存储介质 |
| CN116595285B (zh) * | 2023-07-19 | 2024-04-16 | 深圳复临科技有限公司 | 一种路由生成方法、装置、计算机设备及存储介质 |
| CN119938176A (zh) * | 2024-11-28 | 2025-05-06 | 天翼云科技有限公司 | 后端数据的调度方法、装置、设备、存储介质及程序产品 |
| CN120389993A (zh) * | 2025-06-27 | 2025-07-29 | 苏州元脑智能科技有限公司 | 电子设备以及请求处理方法 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN111580854A (zh) | 2020-08-25 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2021184824A1 (zh) | 基于应用程序接口网关的前后端分离方法及相关设备 | |
| US11095711B2 (en) | DNS Resolution of internal tenant-specific domain addresses in a multi-tenant computing environment | |
| US10452372B2 (en) | Method and deployment module for managing a container to be deployed on a software platform | |
| CN111736775B (zh) | 多源存储方法、装置、计算机系统及存储介质 | |
| US9565265B2 (en) | Method and apparatus for automatically optimizing the loading of images in a cloud-based proxy service | |
| US20090327460A1 (en) | Application Request Routing and Load Balancing | |
| CN112748962B (zh) | 应用加载方法、装置、电子设备和计算机可读介质 | |
| CN111580926A (zh) | 模型发布方法、模型部署方法、装置、设备及存储介质 | |
| US9537932B2 (en) | Emulating test distributed application on server | |
| CN113741952A (zh) | 一种软件包管理方法、装置、设备及介质 | |
| US20170017380A1 (en) | Mobile enabling a web application developed without mobile rendering capabilities | |
| CN112068850A (zh) | 服务产品实例的创建方法、装置及电子设备 | |
| CN111666074B (zh) | 一种web应用定制的方法、相关装置及系统 | |
| CN112115056B (zh) | 一种项目部署方法和装置、服务器、存储介质 | |
| CN119179822A (zh) | 一种网页静态资源的加载方法、装置、设备及存储介质 | |
| CN120179305A (zh) | 基于ArkJS的轻量化前端微应用加载方法及装置 | |
| US20250330376A1 (en) | Service disaster tolerance method, terminal device, software development kit server, and communication system | |
| CN117827185A (zh) | 一种微前端应用页面的生成方法、系统、装置及介质 | |
| HK40030018A (zh) | 基於应用程序接口网关的前後端分离方法及相关设备 | |
| CN117675757A (zh) | 一种小程序平台的后台管理方法、装置、设备及介质 | |
| CN111931083B (zh) | 网页加载方法、装置、终端设备以及可读存储介质 | |
| CN109460531B (zh) | 网页管理方法、装置及智能终端 | |
| CN115629751A (zh) | 一种应用管理方法、装置、计算机设备和存储介质 | |
| US12119987B1 (en) | Layer-specific modifications to network communications according to configurable rules at a proxy | |
| CN114048028A (zh) | 服务调用方法、装置、存储介质和电子设备 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 20925916 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 20925916 Country of ref document: EP Kind code of ref document: A1 |