Skip to content

Commit

Permalink
# Merged branch Angular-auth-implementation into main branch resolvin…
Browse files Browse the repository at this point in the history
…g conflicts
  • Loading branch information
Takudzwamz committed Nov 20, 2023
2 parents b12c8f4 + ec61835 commit d24b972
Show file tree
Hide file tree
Showing 29 changed files with 736 additions and 200 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Deploy to AWS CI/CD with Docker
on:
push:
branches:
#- Angular-auth-implementation
- main
# test push

jobs:
build_and_push_spring:
Expand Down Expand Up @@ -39,22 +39,32 @@ jobs:
docker build -t ${{ secrets.DOCKER_USERNAME }}/lichny-kabinet-patsienta-client:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/lichny-kabinet-patsienta-client:latest
deploy:
needs: [build_and_push_spring, build_and_push_angular]
runs-on: [self-hosted, aws-ec2]
deploy_spring:
needs: build_and_push_spring
runs-on: [self-hosted, spring-aws-ec2]
env:
SPRING_APP_IMAGE: ${{ secrets.DOCKER_USERNAME }}/lichny-kabinet-patsienta-backend:latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Docker login
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | sudo docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Deploy Spring Boot application
run: |
cd backend
echo "SPRING_APP_IMAGE=${SPRING_APP_IMAGE}" > .env
docker-compose down
docker-compose up -d
sudo docker-compose down
sudo docker-compose up -d
deploy_angular:
needs: build_and_push_angular
runs-on: [self-hosted, aws-ec2]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Deploy Angular Universal application
run: |
Expand All @@ -64,5 +74,3 @@ jobs:
docker stop lichny-kabinet-patsienta-client || true
docker rm lichny-kabinet-patsienta-client || true
docker run -d --restart unless-stopped --name lichny-kabinet-patsienta-client -p 80:4000 ${{ secrets.DOCKER_USERNAME }}/lichny-kabinet-patsienta-client:latest
# Test Runner
2 changes: 1 addition & 1 deletion backend/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ services:
app:
image: ${SPRING_APP_IMAGE}
ports:
- "8080:8080"
- "80:8080"
depends_on:
- db
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.http.HttpMethod;

import java.util.Arrays;

@EnableWebSecurity
@RequiredArgsConstructor
Expand All @@ -28,7 +34,15 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
http
.csrf().disable()
.cors().and()
.cors(httpSecurityCorsConfigurer ->
httpSecurityCorsConfigurer.configurationSource(request -> {
CorsConfiguration corsConfig = new CorsConfiguration();
corsConfig.setAllowedOrigins(Arrays.asList("https://lkpatsienta.tech","http://localhost:4200"));
corsConfig.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE","OPTIONS"));
corsConfig.setAllowedHeaders(Arrays.asList("*"));
return corsConfig;
})
)
.authorizeRequests()
.antMatchers("/secured").authenticated()
.antMatchers("/info").authenticated()
Expand All @@ -49,6 +63,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
return http.build();
}


@Bean
public DaoAuthenticationProvider daoAuthenticationProvider(){
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WORKDIR /app

COPY --from=build /app/dist ./dist

EXPOSE 8080
EXPOSE 4000

CMD [ "node", "dist/client/server/main.js" ]

23 changes: 19 additions & 4 deletions client/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/ngx-toastr/toastr.css",
"src/styles.scss"
],
"scripts": [
Expand Down Expand Up @@ -61,7 +62,13 @@
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
"namedChunks": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
Expand All @@ -70,10 +77,12 @@
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "client:build:production"
"browserTarget": "client:build:production",
"proxyConfig": "proxy.conf.json"
},
"development": {
"browserTarget": "client:build:development"
"browserTarget": "client:build:development",
"proxyConfig": "proxy.conf.json"
}
},
"defaultConfiguration": "development"
Expand Down Expand Up @@ -120,7 +129,13 @@
"optimization": false,
"sourceMap": true,
"extractLicenses": false,
"vendorChunk": true
"vendorChunk": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
Expand Down
44 changes: 44 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"@nguniversal/express-engine": "^16.2.0",
"bootstrap": "^5.3.2",
"express": "^4.15.2",
"ngx-spinner": "^16.0.2",
"ngx-toastr": "^17.0.2",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
Expand All @@ -47,4 +49,4 @@
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.1.3"
}
}
}
12 changes: 12 additions & 0 deletions client/proxy.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"/api": {
"target": "https://apilkpatsienta.tech",
"secure": false,
"logLevel": "debug",
"changeOrigin": true,
"pathRewrite": {
"^/api": ""
}
}
}

10 changes: 7 additions & 3 deletions client/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { HomeComponent } from './modules/home/home.component';
import { LoginRegisterComponent } from './components/login-register/login-register.component';
import { MedicalCardComponent } from './components/medical-card/medical-card.component';
import { ChatComponent } from './components/chat/chat.component';
import { AuthGuard } from './core/guards/auth.guard';

const routes: Routes = [
{ path: '', component: HomeComponent, pathMatch: 'full' },
{ path: '', redirectTo: '/login-reg', pathMatch: 'full' },
{ path: 'login-reg', component: LoginRegisterComponent },
{path: 'electronic-medical-card', component: MedicalCardComponent},
{path: 'chat', component: ChatComponent}
{ path: 'profile', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'electronic-medical-card', component: MedicalCardComponent, canActivate: [AuthGuard] },
{ path: 'chat', component: ChatComponent, canActivate: [AuthGuard] },
// ... other routes ...
];


@NgModule({
imports: [RouterModule.forRoot(routes, {
initialNavigation: 'enabledBlocking'
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<app-navbar></app-navbar> <!-- Navigation Bar -->

<ngx-spinner type="pacman" [fullScreen] = "true" bdColor="rgba(51,51,51,0.8)" size="medium" color="#fff"></ngx-spinner>
<!-- Router Outlet will display components based on the route -->
<router-outlet></router-outlet>
<button class="theme-toggle" (click)="toggleTheme()">
Expand Down
32 changes: 27 additions & 5 deletions client/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import { HomeComponent } from './modules/home/home.component';
import { LoginRegisterComponent } from './components/login-register/login-register.component';
import { MedicalCardComponent } from './components/medical-card/medical-card.component';
import { ChatComponent } from './components/chat/chat.component';
import { ReactiveFormsModule } from '@angular/forms';
import { AuthInterceptor } from './core/interceptors/auth.interceptor';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { ErrorInterceptor } from './core/interceptors/error.interceptor';
import { ToastrModule } from 'ngx-toastr';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxSpinnerModule } from 'ngx-spinner';
import { LoadingInterceptor } from './core/interceptors/loading.interceptor';

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Expand All @@ -17,15 +25,29 @@ import { ChatComponent } from './components/chat/chat.component';
HomeComponent,
LoginRegisterComponent,
MedicalCardComponent,
ChatComponent
ChatComponent,
],
imports: [
BrowserModule,
ReactiveFormsModule,
AppRoutingModule,
CoreModule,
SharedModule
SharedModule,
HttpClientModule,
BrowserAnimationsModule,
ToastrModule.forRoot({
positionClass: 'toast-top-center',
preventDuplicates: true,
timeOut: 3000,
// other global options...
}),
NgxSpinnerModule,
],
providers: [],
bootstrap: [AppComponent]
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: LoadingInterceptor, multi: true },
],
bootstrap: [AppComponent],
})
export class AppModule { }
export class AppModule {}
Loading

0 comments on commit d24b972

Please sign in to comment.