Replaced SSR with custom script to prerender metadata for crawlers
This commit is contained in:
1 parent
5091aadcea
commit
26bf465a57
10 files changed
+220
-163
No files matched your search
@@ -1,14 +0,0 @@
|
||||
import {ApplicationConfig, mergeApplicationConfig} from '@angular/core';
|
||||
import {provideServerRendering} from '@angular/platform-server';
|
||||
import {provideServerRoutesConfig} from '@angular/ssr';
|
||||
import {appConfig} from './app.config';
|
||||
import {serverRoutes} from './app.routes.server';
|
||||
|
||||
const serverConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideServerRendering(),
|
||||
provideServerRoutesConfig(serverRoutes)
|
||||
]
|
||||
};
|
||||
|
||||
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
||||
@@ -1,36 +0,0 @@
|
||||
import {RenderMode, ServerRoute} from '@angular/ssr';
|
||||
|
||||
export const serverRoutes: ServerRoute[] = [
|
||||
{
|
||||
path: '',
|
||||
renderMode: RenderMode.Prerender,
|
||||
},
|
||||
{
|
||||
path: 'about',
|
||||
renderMode: RenderMode.Client,
|
||||
},
|
||||
{
|
||||
path: 'portfolio',
|
||||
renderMode: RenderMode.Prerender,
|
||||
},
|
||||
{
|
||||
path: 'blog',
|
||||
renderMode: RenderMode.Prerender,
|
||||
},
|
||||
{
|
||||
path: 'blog/:slug',
|
||||
renderMode: RenderMode.Client,
|
||||
},
|
||||
{
|
||||
path: 'admin',
|
||||
renderMode: RenderMode.Client,
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
renderMode: RenderMode.Client,
|
||||
},
|
||||
{
|
||||
path: '**',
|
||||
renderMode: RenderMode.Client,
|
||||
}
|
||||
]
|
||||
@@ -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;
|
||||
@@ -1,58 +0,0 @@
|
||||
import {AngularNodeAppEngine, createNodeRequestHandler, isMainModule,} from '@angular/ssr/node';
|
||||
import express from 'express';
|
||||
import {dirname, resolve} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
|
||||
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
||||
const browserDistFolder = resolve(serverDistFolder, '../browser');
|
||||
|
||||
const app = express();
|
||||
const angularApp = new AngularNodeAppEngine();
|
||||
|
||||
/**
|
||||
* Example Express Rest API endpoints can be defined here.
|
||||
* Uncomment and define endpoints as necessary.
|
||||
*
|
||||
* Example:
|
||||
* ```ts
|
||||
* app.get('/api/**', (req, res) => {
|
||||
* // Handle API request
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
|
||||
/**
|
||||
* Serve static files from /browser
|
||||
*/
|
||||
app.use(
|
||||
express.static(browserDistFolder, {
|
||||
maxAge: '1y',
|
||||
index: false,
|
||||
redirect: false,
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* Handle all other requests by rendering the Angular application.
|
||||
*/
|
||||
app.use('/**', (req, res, next) => {
|
||||
angularApp.handle(req)
|
||||
.then(response => response ? res.send(response) : next())
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
* Start the server if this module is the main entry point.
|
||||
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
||||
*/
|
||||
if (isMainModule(import.meta.url)) {
|
||||
const port = process.env['PORT'] || 4000;
|
||||
app.listen(port, () => {
|
||||
console.log(`Node Express server listening on http://localhost:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The request handler used by the Angular CLI (dev-server and during build).
|
||||
*/
|
||||
export const reqHandler = createNodeRequestHandler(app);
|
||||
Reference in new issue
Block a user