refactorings
This commit is contained in:
@@ -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);
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user