MCPcopy Index your code
hub / github.com/angular/angular-cli / app

Function app

tests/e2e/assets/ssr-project-webpack/server.ts:11–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9
10// The Express app is exported so that it can be used by serverless Functions.
11export function app(): express.Express {
12 const server = express();
13 const distFolder = join(process.cwd(), 'dist/ssr-project-webpack/browser');
14 const indexHtml = existsSync(join(distFolder, 'index.original.html'))
15 ? join(distFolder, 'index.original.html')
16 : join(distFolder, 'index.html');
17
18 const commonEngine = new CommonEngine();
19
20 server.set('view engine', 'html');
21 server.set('views', distFolder);
22
23 // Example Express Rest API endpoints
24 // server.get('/api/**', (req, res) => { });
25 // Serve static files from /browser
26 server.get(
27 '*.*',
28 express.static(distFolder, {
29 maxAge: '1y',
30 }),
31 );
32
33 // All regular routes use the Angular engine
34 server.get('*', (req, res, next) => {
35 const { protocol, originalUrl, baseUrl, headers } = req;
36
37 commonEngine
38 .render({
39 bootstrap: AppServerModule,
40 documentFilePath: indexHtml,
41 url: `${protocol}://${headers.host}${originalUrl}`,
42 publicPath: distFolder,
43 providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
44 })
45 .then((html) => res.send(html))
46 .catch((err) => next(err));
47 });
48
49 return server;
50}
51
52function run(): void {
53 const port = process.env['PORT'] || 4000;

Callers 1

runFunction · 0.85

Calls 7

renderMethod · 0.95
joinFunction · 0.85
existsSyncFunction · 0.85
sendMethod · 0.80
getMethod · 0.65
nextFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected