Fix standalone problem

pull/2/head
Alvaro Puente Mella 2024-05-22 13:44:44 +02:00
parent e8e5d8eb5d
commit 3f0906d8c7
38 changed files with 495 additions and 1546 deletions

View File

@ -1,4 +1,4 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
# See http://help.github.com/ignore-files/ for more about ignoring files.
# Compiled output
/dist

View File

@ -1,6 +1,6 @@
# OgWebconsole
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.3.7.
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.0.7.
## Development server

View File

@ -5,7 +5,17 @@
"projects": {
"ogWebconsole": {
"projectType": "application",
"schematics": {},
"schematics": {
"@schematics/angular:component": {
"standalone": false
},
"@schematics/angular:directive": {
"standalone": false
},
"@schematics/angular:pipe": {
"standalone": false
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
@ -25,15 +35,9 @@
"src/assets"
],
"styles": [
"src/custom-theme.scss",
"src/styles.css"
],
"scripts": [],
"server": "src/main.server.ts",
"prerender": true,
"ssr": {
"entry": "server.ts"
}
"scripts": []
},
"configurations": {
"production": {

File diff suppressed because it is too large Load Diff

View File

@ -6,42 +6,33 @@
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"serve:ssr:ogWebconsole": "node dist/og-webconsole/server/server.mjs"
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^17.3.0",
"@angular/cdk": "^17.3.9",
"@angular/common": "^17.3.0",
"@angular/compiler": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/forms": "^17.3.0",
"@angular/material": "^17.3.9",
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@angular/platform-server": "^17.3.0",
"@angular/router": "^17.3.0",
"@angular/ssr": "^17.3.7",
"bootstrap": "^5.3.3",
"express": "^4.18.2",
"@angular/animations": "^17.0.0",
"@angular/common": "^17.0.0",
"@angular/compiler": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/forms": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
"zone.js": "~0.14.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.3.7",
"@angular/cli": "^17.3.7",
"@angular/compiler-cli": "^17.3.0",
"@types/express": "^4.17.17",
"@angular-devkit/build-angular": "^17.0.7",
"@angular/cli": "^17.0.7",
"@angular/compiler-cli": "^17.0.0",
"@types/jasmine": "~5.1.0",
"@types/node": "^18.18.0",
"jasmine-core": "~5.1.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.4.2"
"typescript": "~5.2.2"
}
}
}

View File

@ -1,56 +0,0 @@
import { APP_BASE_HREF } from '@angular/common';
import { CommonEngine } from '@angular/ssr';
import express from 'express';
import { fileURLToPath } from 'node:url';
import { dirname, join, resolve } from 'node:path';
import bootstrap from './src/main.server';
// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
const server = express();
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
const browserDistFolder = resolve(serverDistFolder, '../browser');
const indexHtml = join(serverDistFolder, 'index.server.html');
const commonEngine = new CommonEngine();
server.set('view engine', 'html');
server.set('views', browserDistFolder);
// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(browserDistFolder, {
maxAge: '1y'
}));
// All regular routes use the Angular engine
server.get('*', (req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;
commonEngine
.render({
bootstrap,
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: browserDistFolder,
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
})
.then((html) => res.send(html))
.catch((err) => next(err));
});
return server;
}
function run(): void {
const port = process.env['PORT'] || 4000;
// Start up the Node server
const server = app();
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
run();

View File

@ -0,0 +1,34 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MainLayoutComponent } from './components/layout/main-layout/main-layout.component';
import { AuthLayoutComponent } from './components/layout/auth-layout/auth-layout.component';
import { LoginComponent } from './components/login/login.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { PageNotFoundComponent } from './components/page-not-found/page-not-found.component';
const routes: Routes = [
{ path: '', redirectTo: 'auth/login', pathMatch: 'full' },
{
path: '',
component: MainLayoutComponent,
children: [
{ path: 'dashboard', component: DashboardComponent },
// otras rutas que usan el MainLayoutComponent
],
},
{
path: 'auth',
component: AuthLayoutComponent,
children: [
{ path: 'login', component: LoginComponent },
// otras rutas de autenticación
],
},
{ path: '**', component: PageNotFoundComponent },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

View File

@ -1,10 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent],
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
});
@ -14,7 +20,7 @@ describe('AppComponent', () => {
expect(app).toBeTruthy();
});
it(`should have the 'ogWebconsole' title`, () => {
it(`should have as title 'ogWebconsole'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('ogWebconsole');

View File

@ -1,15 +1,7 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { SidebarComponent } from './components/layout/sidebar/sidebar.component';
import { FooterComponent } from './components/layout/footer/footer.component';
import { HeaderComponent } from './components/layout/header/header.component';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, SidebarComponent, FooterComponent, HeaderComponent, FormsModule, HttpClientModule],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})

View File

@ -1,11 +0,0 @@
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering } from '@angular/platform-server';
import { appConfig } from './app.config';
const serverConfig: ApplicationConfig = {
providers: [
provideServerRendering()
]
};
export const config = mergeApplicationConfig(appConfig, serverConfig);

View File

@ -1,11 +0,0 @@
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { provideClientHydration } from '@angular/platform-browser';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { provideHttpClient } from '@angular/common/http';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes), provideClientHydration(), provideAnimationsAsync(), provideHttpClient(),]
};

View File

@ -0,0 +1,35 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AuthLayoutComponent } from './components/layout/auth-layout/auth-layout.component';
import { MainLayoutComponent } from './components/layout/main-layout/main-layout.component';
import { FooterComponent } from './components/layout/footer/footer.component';
import { HeaderComponent } from './components/layout/header/header.component';
import { SidebarComponent } from './components/layout/sidebar/sidebar.component';
import { LoginComponent } from './components/login/login.component';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent,
AuthLayoutComponent,
MainLayoutComponent,
FooterComponent,
HeaderComponent,
SidebarComponent,
LoginComponent,
MainLayoutComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

View File

@ -1,30 +0,0 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MainLayoutComponent } from './components/layout/main-layout/main-layout.component';
import { AuthLayoutComponent } from './components/layout/auth-layout/auth-layout.component';
import { LoginComponent } from './components/login/login.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { PageNotFoundComponent } from './components/page-not-found/page-not-found.component';
import {AuthGuard } from './auth.guard';
export const routes: Routes = [
{ path: '', redirectTo: 'auth/login', pathMatch: 'full' },
{
path: '',
component: MainLayoutComponent,
pathMatch: 'full', canActivate: [AuthGuard],
children: [
{ path: 'dashboard', component: DashboardComponent },
// otras rutas que usan el MainLayoutComponent
],
},
{
path: 'auth',
component: AuthLayoutComponent,
children: [
{ path: 'login', component: LoginComponent },
// otras rutas de autenticación
],
},
{ path: '**', component: PageNotFoundComponent },
];

View File

@ -1,17 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { CanActivateFn } from '@angular/router';
import { authGuard } from './auth.guard';
describe('authGuard', () => {
const executeGuard: CanActivateFn = (...guardParameters) =>
TestBed.runInInjectionContext(() => authGuard(...guardParameters));
beforeEach(() => {
TestBed.configureTestingModule({});
});
it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});

View File

@ -1,24 +0,0 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from './auth.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) { }
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const token = this.authService.getToken();
if (token) {
return true;
} else {
this.router.navigate(['/login']);
return false;
}
}
}

View File

@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { AuthService } from './auth.service';
describe('AuthService', () => {
let service: AuthService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AuthService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -1,33 +0,0 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class AuthService {
private apiUrl = 'http://127.0.0.1:8080/auth/login'; // Reemplaza con la URL de tu API
constructor(private http: HttpClient) { }
login(username: string, password: string): Observable<any> {
return this.http.post<any>(this.apiUrl, { username, password }).pipe(
tap(response => {
if (response.token) {
localStorage.setItem('token', response.token);
localStorage.setItem('refresh_token', response.refresh_token);
}
})
);
}
logout(): void {
localStorage.removeItem('token');
localStorage.removeItem('refresh_token');
}
getToken(): string | null {
return localStorage.getItem('token');
}
}

View File

@ -2,8 +2,6 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-dashboard',
standalone: true,
imports: [],
templateUrl: './dashboard.component.html',
styleUrl: './dashboard.component.css'
})

View File

@ -2,5 +2,4 @@
<div class="auth-content">
<router-outlet></router-outlet>
</div>
</div>
</div>

View File

@ -8,7 +8,7 @@ describe('AuthLayoutComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AuthLayoutComponent]
declarations: [AuthLayoutComponent]
})
.compileComponents();

View File

@ -1,11 +1,9 @@
import { HttpClientModule } from '@angular/common/http';
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-auth-layout',
standalone: true,
imports: [RouterOutlet, HttpClientModule],
templateUrl: './auth-layout.component.html',
styleUrl: './auth-layout.component.css'
})

View File

@ -2,8 +2,6 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-footer',
standalone: true,
imports: [],
templateUrl: './footer.component.html',
styleUrl: './footer.component.css'
})

View File

@ -2,8 +2,6 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-header',
standalone: true,
imports: [],
templateUrl: './header.component.html',
styleUrl: './header.component.css'
})

View File

@ -1,15 +0,0 @@
:host{
width: 100%;
display: grid;
grid-template-areas:
"sidebar header"
"sidebar content"
"sidebar footer";
grid-template-columns: 120px 1fr;
height: 100%;
}
.content-wrapper{
display: block;
background-color: gold;
grid-area: content;
}

View File

@ -1,7 +1 @@
<app-sidebar></app-sidebar>
<app-header></app-header>
<app-footer></app-footer>
<div class="content-wrapper">
<div class="content">
<router-outlet />
</div>
<p>main-layout works!</p>

View File

@ -8,7 +8,7 @@ describe('MainLayoutComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MainLayoutComponent]
declarations: [MainLayoutComponent]
})
.compileComponents();

View File

@ -1,13 +1,7 @@
import { Component } from '@angular/core';
import { SidebarComponent } from '../sidebar/sidebar.component';
import { FooterComponent } from '../footer/footer.component';
import { HeaderComponent } from '../header/header.component';
import { RouterOutlet } from '@angular/router';
@Component({
selector: 'app-main-layout',
standalone: true,
imports: [SidebarComponent, FooterComponent, HeaderComponent, RouterOutlet],
templateUrl: './main-layout.component.html',
styleUrl: './main-layout.component.css'
})

View File

@ -2,8 +2,6 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-sidebar',
standalone: true,
imports: [],
templateUrl: './sidebar.component.html',
styleUrl: './sidebar.component.css'
})

View File

@ -1,14 +1,14 @@
<div>
<h2>Login</h2>
<form (ngSubmit)="login()">
<form>
<div>
<label for="username">Username:</label>
<input (ngModel)="username" type="text" id="username" name="username" required>
<input [(ngModel)]="loginObj.EmailId" type="text" id="username" name="EmailId" required>
</div>
<div>
<label for="password">Password:</label>
<input (ngModel)="password" type="password" id="password" name="password" required>
<input (ngModel)="loginObj.Password" type="password" id="password" name="Password" required>
</div>
<button type="submit">Login</button>
<button (click)="onLogin()">Login</button>
</form>
</div>

View File

@ -1,5 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { AuthService } from '../../auth.service';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';
@ -9,20 +10,12 @@ import { Router } from '@angular/router';
styleUrls: ['./login.component.css'],
})
export class LoginComponent {
username: string = '';
password: string = '';
constructor(private authService: AuthService, private router: Router) { }
login(): void {
this.authService.login(this.username, this.password).subscribe(
response => {
console.log('Login successful');
this.router.navigate(['/']);
},
error => {
console.error('Login failed', error);
}
);
}
loginObj: any = {
"EmailId": "",
"Password": ""
};
constructor(private http: HttpClient) { }
onLogin() {
this.http.post('https://freeapi.gerasim.in/api/User/Login', this.loginObj)
}
}

View File

@ -2,8 +2,6 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-page-not-found',
standalone: true,
imports: [],
templateUrl: './page-not-found.component.html',
styleUrl: './page-not-found.component.css'
})

View File

@ -1,37 +0,0 @@
// Custom Theming for Angular Material
// For more information: https://material.angular.io/guide/theming
@use '@angular/material' as mat;
// Plus imports for other components in your app.
// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// Be sure that you only ever include this mixin once!
@include mat.core();
// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue. Available color palettes: https://material.io/design/color/
$ogWebconsole-primary: mat.define-palette(mat.$indigo-palette);
$ogWebconsole-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
// The warn palette is optional (defaults to red).
$ogWebconsole-warn: mat.define-palette(mat.$red-palette);
// Create the theme object. A theme consists of configurations for individual
// theming systems such as "color" or "typography".
$ogWebconsole-theme: mat.define-light-theme((
color: (
primary: $ogWebconsole-primary,
accent: $ogWebconsole-accent,
warn: $ogWebconsole-warn,
),
typography: mat.define-typography-config(),
density: 0
));
// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
@include mat.all-component-themes($ogWebconsole-theme);

View File

@ -6,10 +6,8 @@
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body class="mat-typography">
<body>
<app-root></app-root>
</body>
</html>

View File

@ -1,7 +0,0 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { config } from './app/app.config.server';
const bootstrap = () => bootstrapApplication(AppComponent, config);
export default bootstrap;

View File

@ -1,6 +1,7 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
bootstrapApplication(AppComponent, appConfig)
.catch((err) => console.error(err));
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));

View File

@ -1,7 +1 @@
/* You can add global styles to this file, and also import other style files */
html, body { height: 100%;
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}

View File

@ -3,14 +3,10 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [
"node"
]
"types": []
},
"files": [
"src/main.ts",
"src/main.server.ts",
"server.ts"
"src/main.ts"
],
"include": [
"src/**/*.d.ts"

View File

@ -3,6 +3,7 @@
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,