MCPcopy
hub / github.com/rx-angular/rx-angular / app

Function app

apps/ssr/server.ts:10–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

runFunction · 0.70

Calls 4

renderMethod · 0.65
nextFunction · 0.50
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected