Closed ComLock closed 5 years ago
import {request as httpClientRequest} from '/lib/http-client';
import {toStr} from '/lib/enonic/util';
import {getBaseUri} from '/lib/xp/admin';
export function isAppRunning(applicationKey) {
const url = `http://localhost:8080${getBaseUri()}/rest/application`; // TODO Remove hardcode
const reqParams = {
url,
params: {
applicationKey
},
auth: {
user: 'su',
password: 'password' // TODO Remove hardcode
}
}; //log.info(toStr({reqParams}));
let res;
try {
res = httpClientRequest(reqParams); log.info(toStr({res}));
if (res.status !== 200) {
const errMsg = `Requesting url:${url} got status:${res.status}`;
log.error(errMsg);
throw new Error(errMsg);
}
} catch (e) {
const errMsg = `Something went wrong trying request url:${url}`;
log.error(errMsg);
throw new Error(errMsg);
}
let body;
try {
body = JSON.parse(res.body); log.info(toStr({body}));
} catch (e) {
const errMsg = `Something went wrong trying to json parse response.body from url:${url}`;
log.error(errMsg);
throw new Error(errMsg);
}
return body.state === 'started';
}
Our Web API is internal and endpoints require authentication. If we open them outside, we have to implement authentication via token/API key. I suggest we focus on improving/expanding our JS API for now (like https://github.com/enonic/xp/issues/6671 for example).
There are many web api's used in the admin apps, that are not documented.
For example its possible to list app statuses, and start and stop apps. If they where documented people would know that they exist and be able to use them for cool stuff.
In addition it would also be useful if those same web api's where available as js api's.