createServer

1import { createServer } from '@ng-rsbuild/plugin-angular/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(bootstrap: any): RsbuildAngularServer; 2

Examples

The following example shows how to create a standard express server:

myapp/src/server.ts
1import { createServer } from '@ng-rsbuild/plugin-angular/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

RsbuildAngularServer

1export interface RsbuildAngularServer { 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.