-
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.
feat(@schematics/angular): update
ng new
to use the esbuild applica…
…tion builder based builder This commit updates the `ng generate application` to use the esbuild `application` builder. This also updates the schematics to support both `browser` and `application` builders. BREAKING CHANGE: `rootModuleClassName`, `rootModuleFileName` and `main` options have been removed from the public `pwa` and `app-shell` schematics.
- Loading branch information
1 parent
3d3afc7
commit 3f8aa9d
Showing
37 changed files
with
953 additions
and
700 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
53 changes: 53 additions & 0 deletions
53
packages/angular/ssr/schematics/ng-add/files/application-builder/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,53 @@ | ||
import { APP_BASE_HREF } from '@angular/common'; | ||
import { CommonEngine } from '@angular/ssr'; | ||
import express from 'express'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { dirname, join } from 'node:path'; | ||
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> 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 browserDistFolder = dirname(fileURLToPath(import.meta.url)); | ||
const indexHtml = join(browserDistFolder, '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) => { | ||
commonEngine | ||
.render({ | ||
<% if (isStandalone) { %>bootstrap<% } else { %>bootstrap: AppServerModule<% } %>, | ||
documentFilePath: indexHtml, | ||
url: req.originalUrl, | ||
publicPath: browserDistFolder, | ||
providers: [{ provide: APP_BASE_HREF, useValue: req.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(); |
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.