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

Function updateServerFileForEsbuild

tests/e2e/utils/project.ts:186–246  ·  view source on GitHub ↗
(filepath: string)

Source from the content-addressed store, hash-verified

184}
185
186export function updateServerFileForEsbuild(filepath: string): Promise<void> {
187 return writeFile(
188 filepath,
189 `
190 import { APP_BASE_HREF } from '@angular/common';
191 import { CommonEngine } from '@angular/ssr/node';
192 import express from 'express';
193 import { join, resolve } from 'node:path';
194 import bootstrap from './main.server';
195
196 // The Express app is exported so that it can be used by serverless Functions.
197 export function app(): express.Express {
198 const server = express();
199 const serverDistFolder = import.meta.dirname;
200 const browserDistFolder = resolve(serverDistFolder, '../browser');
201 const indexHtml = join(serverDistFolder, 'index.server.html');
202
203 const commonEngine = new CommonEngine();
204
205 server.set('view engine', 'html');
206 server.set('views', browserDistFolder);
207
208 server.use(express.static(browserDistFolder, {
209 maxAge: '1y',
210 index: false,
211 }));
212
213 // All regular routes use the Angular engine
214 server.use((req, res, next) => {
215 const { protocol, originalUrl, baseUrl, headers } = req;
216
217 commonEngine
218 .render({
219 bootstrap,
220 documentFilePath: indexHtml,
221 url: \`\${protocol}://\${headers.host}\${originalUrl}\`,
222 publicPath: browserDistFolder,
223 providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
224 })
225 .then((html) => res.send(html))
226 .catch((err) => next(err));
227 });
228
229 return server;
230 }
231
232 function run(): void {
233 const port = process.env['PORT'] || 4000;
234 const server = app();
235 server.listen(port, (error) => {
236 if (error) {
237 throw error;
238 }
239 console.log(\`Node Express server listening on http://localhost:\${port}\`);
240 });
241 }
242
243 run();

Callers

nothing calls this directly

Calls 1

writeFileFunction · 0.90

Tested by

no test coverage detected