dev_in_progress
dev_in_progress

Reputation: 2494

Ping Angular 2 application

I have Angular 2 application on one server and Java application on other.

I want to ping Angular application from Java to check status (is it up or down).

Is there a way to make Angular 2 RESTful API to serve that data, or do i need something on Node.js to check app status (make rest api there?)??

Any help is appreciated

Upvotes: 1

Views: 1163

Answers (2)

Vinko Vorih
Vinko Vorih

Reputation: 2202

I'm giving you example in Java code. So what you need to do is create a thread that (scheduled or not; I'm using cron scheduler in this example) will try to access http://localhost:4200 which is by default your angular2 server.

public class AppConfig{
@Autowired
RequestStatus reqStat;

@Scheduled(cron="0 */5 0-3,5-23 * * *")
public void checkAvailability() 
{

    if(!reqStat.fetchProduction()){
        //do something
}




public class RequestStatus {

public boolean fetchProduction() {

    boolean result = false;
    try {
        URL url = new URL("http://localhost:4200/");
        url.openStream();
        result = true;
    } catch (Exception ex) {
    }
    return result;
}



public class CheckAvailabilityThread{

@Autowired
RequestStatus reqStat;
}

Also, if you want to do it in JS, status code 200 in Response header will do your job.

Upvotes: 1

duongthaiha
duongthaiha

Reputation: 855

Depend on what you want to check really.

A 200 response from website is enough?

Or you want to make sure some logic is working as well. If it is the case then we have a route in Angular app this do a quick check on critical APIs and return a 200 if OK and 400 if it is not. For example: domain.com/status/probe

Upvotes: 0

Related Questions