This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bootstrapApplication } from "@angular/platform-browser"; | |
import { AppComponent } from "./app/app.component"; | |
import { HttpHandlerFn, HttpRequest, provideHttpClient, withInterceptors } from "@angular/common/http"; | |
import { provideRouter } from "@angular/router"; | |
import { inject } from "@angular/core"; | |
import { HeaderService } from "./app/header.service"; | |
import { MY_ROUTES } from "./app/app.routes"; | |
bootstrapApplication(AppComponent, { | |
providers: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { AppRoutingModule } from './app-routing.module'; | |
import { AppComponent } from './app.component'; | |
import { HTTP_INTERCEPTORS, HttpClientModule } from "@angular/common/http"; | |
import { MyInterceptor } from "./my-interceptor"; | |
@NgModule({ | |
declarations: [ | |
AppComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from "@angular/core"; | |
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http"; | |
import { Observable } from "rxjs"; | |
import { HeaderService } from "./header.service"; | |
@Injectable() | |
export class MyInterceptor implements HttpInterceptor { | |
constructor(private headerService: HeaderService) { | |
} | |
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>home works and can be reached using functional guards!</p> | |
<p *ngIf="open">Hello there</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { NgIf } from '@angular/common'; | |
@Component({ | |
selector: 'app-home', | |
standalone: true, | |
imports: [NgIf], | |
templateUrl: './home.component.html', | |
styleUrls: ['./home.component.scss'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const routes: Routes = [ | |
{ | |
path: 'home', | |
loadComponent: () => import('./home/home.component').then(m => m.HomeComponent), | |
canActivate: [(): boolean => inject(AuthService).isAuthenticated()] | |
} | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class AuthGuard implements CanActivate { | |
constructor(private authService: AuthService) {} | |
canActivate( | |
route: ActivatedRouteSnapshot, | |
state: RouterStateSnapshot | |
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const routes: Routes = [ | |
{ | |
path: 'home', | |
loadComponent: () => import('./home/home.component').then(m => m.HomeComponent), | |
canActivate: [AuthGuard] | |
} | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.example.api; | |
import com.example.example.service.AppService; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.List; | |
@RestController | |
@RequestMapping("/api/data") | |
public class AppController { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get, Param, Query, Res } from '@nestjs/common'; | |
import { AppService } from './app.service'; | |
import { Response } from 'express'; | |
@Controller('api/data') | |
export class AppController { | |
constructor(private readonly appService: AppService) {} | |
@Get(':id') | |
async getData( |
NewerOlder