angular/integration/platform-server/src/server.ts
Paul Gschwendtner 859ca504f8 test: run platform-server integration test with v13 partial compilation packages (#43431)
Updates the platform-server integration test to rely on the v13 partial
compilation packages. This involves setting up the Babel linker plugin.
This is a great addition for coverage of the Babel linker plugin.

PR Close #43431
2021-10-01 18:28:44 +00:00

44 lines
1.5 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
require('zone.js/bundles/zone-node.umd.js');
import {enableProdMode, Type} from '@angular/core';
import {renderModule} from '@angular/platform-server';
import * as express from 'express';
import {HelloWorldServerModule} from './helloworld/app.server';
const {default: helloworld} = require('raw-loader!./helloworld/index.html');
import {TransferStateServerModule} from './transferstate/app.server';
const {default: transferstate} = require('raw-loader!./transferstate/index.html');
const app = express();
function render(moduleType: Type<any>, html: string) {
return (req, res) => {
renderModule(moduleType, {
document: html,
url: req.url,
}).then((response) => { res.send(response); });
};
}
enableProdMode();
// Client bundles will be statically served from the built/ directory.
app.use('/webpack-out', express.static('webpack-out'));
// Keep the browser logs free of errors.
app.get('/favicon.ico', (req, res) => { res.send(''); });
//-----------ADD YOUR SERVER SIDE RENDERED APP HERE ----------------------
app.get('/helloworld', render(HelloWorldServerModule, helloworld));
app.get('/transferstate', render(TransferStateServerModule, transferstate));
app.listen(4206, function() { console.log('Server listening on port 4206!'); });