-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@schematics/angular): enable opt-in for new
@angular/ssr
feature
This commit updates several schematics to make the new `@angular/ssr` feature opt-in. Users can opt in by using the `--server-routing` option or by responding with `yes` to the prompt. (cherry picked from commit 43cd458)
- Loading branch information
1 parent
af95f2f
commit 4e2a5fe
Showing
31 changed files
with
168 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...s/angular/server/files/application-builder/ngmodule-src/app/app.module.server.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ServerModule } from '@angular/platform-server'; | ||
import { provideServerRoutesConfig } from '@angular/ssr'; | ||
import { ServerModule } from '@angular/platform-server';<% if(serverRouting) { %> | ||
import { provideServerRoutesConfig } from '@angular/ssr';<% } %> | ||
import { AppComponent } from './app.component'; | ||
import { AppModule } from './app.module'; | ||
import { serverRoutes } from './app.routes.server'; | ||
import { AppModule } from './app.module';<% if(serverRouting) { %> | ||
import { serverRoutes } from './app.routes.server';<% } %> | ||
|
||
@NgModule({ | ||
imports: [AppModule, ServerModule], | ||
providers: [provideServerRoutesConfig(serverRoutes)], | ||
imports: [AppModule, ServerModule],<% if(serverRouting) { %> | ||
providers: [provideServerRoutesConfig(serverRoutes)],<% } %> | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppServerModule {} |
12 changes: 6 additions & 6 deletions
12
...angular/server/files/application-builder/standalone-src/app/app.config.server.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/schematics/angular/ssr/files/application-builder-common-engine/server.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { APP_BASE_HREF } from '@angular/common'; | ||
import { CommonEngine, isMainModule } from '@angular/ssr/node'; | ||
import express from 'express'; | ||
import { dirname, join, resolve } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> from './main.server'; | ||
|
||
const serverDistFolder = dirname(fileURLToPath(import.meta.url)); | ||
const browserDistFolder = resolve(serverDistFolder, '../<%= browserDistDirectory %>'); | ||
const indexHtml = join(serverDistFolder, 'index.server.html'); | ||
|
||
const app = express(); | ||
const commonEngine = new CommonEngine(); | ||
|
||
/** | ||
* 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 /<%= browserDistDirectory %> | ||
*/ | ||
app.get( | ||
'**', | ||
express.static(browserDistFolder, { | ||
maxAge: '1y', | ||
index: 'index.html' | ||
}), | ||
); | ||
|
||
/** | ||
* Handle all other requests by rendering the Angular application. | ||
*/ | ||
app.get('**', (req, res, next) => { | ||
const { protocol, originalUrl, baseUrl, headers } = req; | ||
|
||
commonEngine | ||
.render({ | ||
<% if (isStandalone) { %>bootstrap<% } else { %>bootstrap: AppServerModule<% } %>, | ||
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)); | ||
}); | ||
|
||
/** | ||
* 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}`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.