refactorings

This commit is contained in:
2026-05-15 14:06:38 +02:00
parent 24862a33d0
commit 17cb23aa40
16 changed files with 398 additions and 309 deletions
-11
View File
@@ -1,11 +0,0 @@
import { provideServerRendering } from '@angular/ssr';
import type { ApplicationConfig } from '@angular/core';
import { mergeApplicationConfig } from '@angular/core';
import { appConfig } from './app.config';
const serverConfig: ApplicationConfig = {
providers: [provideServerRendering()],
};
export const config: ApplicationConfig = mergeApplicationConfig(appConfig, serverConfig);
-12
View File
@@ -1,12 +0,0 @@
import type { BootstrapContext } from '@angular/platform-browser';
import { bootstrapApplication } from '@angular/platform-browser';
import type { ApplicationRef } from '@angular/core';
import { AppComponent } from './app/app.component';
import { config } from './app/app.config.server';
const bootstrap: (context: BootstrapContext) => Promise<ApplicationRef> = (
context: BootstrapContext,
): Promise<ApplicationRef> => bootstrapApplication(AppComponent, config, context);
export default bootstrap;
-54
View File
@@ -1,54 +0,0 @@
import { APP_BASE_HREF } from '@angular/common';
import { CommonEngine, isMainModule } from '@angular/ssr/node';
import type { Express, NextFunction, Request, Response } from 'express';
import express from 'express';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import bootstrap from './main.server';
const serverDistFolder: string = dirname(fileURLToPath(import.meta.url));
const browserDistFolder: string = resolve(serverDistFolder, '../browser');
const indexHtml: string = join(serverDistFolder, 'index.server.html');
const allowedHosts: readonly string[] = [
'fraujulian.xyz',
'www.fraujulian.xyz',
'test.fraujulian.xyz',
'localhost',
'127.0.0.1',
];
const app: Express = express();
const commonEngine: CommonEngine = new CommonEngine({ allowedHosts });
app.use(
express.static(browserDistFolder, {
maxAge: '1y',
index: 'index.html',
}),
);
app.get('/{*splat}', (req: Request, res: Response, next: NextFunction): void => {
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: string): Response => res.send(html))
.catch((err: Error): void => next(err));
});
if (isMainModule(import.meta.url)) {
const port: number = 3000;
app.listen(port, (): void => {
console.log(`Listening on port ${port}`);
});
}
export default app;