Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Using http.get to get page from frontend

Post

Using http.get to get page from frontend

+1
−0

It's possible to use Angular 8 http.get to get a page from the frontend itself ?

My local frontend url: https://192.168.0.177:4200/

I tried in a service:

test(): Observable<string> {
	return this.http
		.get<string>(`https://192.168.0.177:4200/ping`)
		.pipe(catchError(this.processHTTPMsgService.handleError));
}

but I got a 404:

Console:

GET https://192.168.0.177:4200/ping 404 (Not Found)
ERROR 404 - Not Found <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /ping</pre>
</body>
</html>

This has an hardcoded url because it's just a test. My FE is on port 4200 and my backend in 3443.

https://192.168.0.177:4200/ping url load correctly if I put it directly on browser.

The /ping url is an Angular component with only a PING string inside:

ping.component.ts:

import { Component } from '@angular/core';

@Component({
	selector: 'app-ping',
	templateUrl: './ping.component.html'
})
export class PingComponent {

	constructor() { }
}

ping.component.html:

PING

I call service.test() from some other component this way:

test(): void {
	this.myService.test().subscribe(test=>{
		console.log('test', test); // Should result in PING
	})
}

I also tried with axios:

	axios.get('https://192.168.0.177:4200/ping').then(ping=>{
		console.log('ping', ping);
	}).catch(err=>{
		console.log('ping error', err);
	});

with same result.

What I'm trying to do here ? I develop an Angular video application that shows live video stream that take too long. It has a Keycloak login that has an idle limit. So I'm trying to simulate user action in order to make keycloak know it's alive and don't logout automatically.

Any help appreciated. Thanks.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Alternative approach (2 comments)
Alternative approach
Alexei‭ wrote over 2 years ago

I am not sure why it fails for you (does switching to HTTP makes it work?), but I do not think it is the correct approach. You might try getting a new token on expiration as indicated here.

nelson777‭ wrote over 2 years ago

I'm updating the tokens correctly. The problem is that besides token expiration Keycloak has another setting called "Idle time". And even renewing tokens when they expire, if there isn't an action from the user, the application is considered "Idle". Thus the problem.