GW Web API
Usage
Introduce dependent libraries
import axios from 'axios'; //Network request library
import qs from "qs"; //Library that parses URLs into objects
Parse the token and api parameters spliced on the current web page address
let query = location.href.split("?")[1];
let {token, api} = qs.parse(query);
let context = {}
Initiate a network request on the api path on the web page address to obtain appId, session, loginUrl
axios.post(api, {
token: token
}).then(rep => {
console.log('response', rep);
context.appId = rep.data.appId;
context.session = rep.data.session;
context.loginUrl = rep.data.loginUrl;
doRequest();
}).catch(e => {
console.log(e);
})
Use the obtained CUTOS session information to send its own service network request
function doRequest() {
let counter = 0;
let handler = setInterval(function () {
test();
//The test here is the session and appId information based on the CUTOS system, packaging its own service network request, and needs to include both information in the headers.
counter++;
if (counter >= 10) {
clearInterval(handler);
}
}, 1000);
}
function test() {
axios.get('http://localhost:8080/test', {
headers: {
appId: context.appId,
session: context.session
}
}).then(rep => {
}).catch(e => {
console.log(e);
if (e.response.status === 401) {
window.location = context.loginUrl;
}
});
}
The network request called by function test needs to match the definition on the Java side. 'http://localhost:8080/test' is the enabling address of the java service.
Run
1. Enable java side code
2. Enable web-side code
3. Open cutos background system-gateway management-application service management, find the corresponding app-open
The URL after opening, for example: http://localhost:5000/index.html?token=997189f2-bce1-4476-b84f-1af8fc0b59cb&api=https://www.cut-os.com/rest/sv/gw/app/admin/token_session