createServer
1import { createServer } from '@nx/angular-rspack/ssr';
2
The createServer
function is used to setup Angular's CommonEngine
using an express
server. It takes the bootstrap function as an argument, which is the function that bootstraps the Angular server application. This is usually main.server.ts
. It returns RsbuildAngularServer
which contains the server instance to allow further modifications as well as the listen method to start the server.
1function createServer(
2 bootstrap: any,
3 opts?: RspackAngularServerOptions
4): RspackAngularServer;
5
Examples
The following example shows how to create a standard express server:
1import { createServer } from '@nx/angular-rspack/ssr';
2import bootstrap from './main.server';
3
4const server = createServer(bootstrap);
5
6/** Add your custom server logic here
7 *
8 * For example, you can add a custom static file server:
9 *
10 * server.app.use('/static', express.static(staticFolder));
11 *
12 * Or add additional api routes:
13 *
14 * server.app.get('/api/hello', (req, res) => {
15 * res.send('Hello World!');
16 * });
17 *
18 * Or add additional middleware:
19 *
20 * server.app.use((req, res, next) => {
21 * res.send('Hello World!');
22 * });
23 */
24
25server.listen();
26
RspackAngularServer
1export interface RspackAngularServer {
2 app: express.Express;
3 listen: (port?: number) => void;
4}
5
app
express.Express
The express application instance.
listen
(port?: number) => void
Starts the express application on the specified port. If no port is provided, the default port (4000) is used.
RspackAngularServerOptions
1export interface RspackAngularServerOptions {
2 serverDistFolder?: string;
3 browserDistFolder?: string;
4 indexHtml?: string;
5}
6
serverDistFolder
string
The folder where the server bundle is located. Defaults to the dist/server
folder.
browserDistFolder
string
The folder where the browser bundle is located. Defaults to the dist/browser
folder.
indexHtml
string
The path to the index.html file. Defaults to the index.html
file in the browserDistFolder
.