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.

Post History

60%
+1 −0
Q&A Using http.get to get page from frontend

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> { ret...

1 answer  ·  posted 3y ago by nelson777‭  ·  last activity 3y ago by Derek Elkins‭

#1: Initial revision by user avatar nelson777‭ · 2021-09-02T00:02:39Z (over 3 years ago)
Using http.get to get page from frontend
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.