Serving the Angular Universal App with Nest.js
Now that we are going to be serving the Angular app with our Nest.js server, we are going to have to compile them together so that when our Nest.js server is run, it knows where to look for the Universal app. In our server/src/main.ts
file there are a couple of key things we need to have in there. Here we create a function bootstrap()
and then call it from below.
async
function
bootstrap() {
if
(
environment
.
production
)
{
enableProdMode
();
}
const
app
=
await
NestFactory
.
create
(
ApplicationModule
.
module
Factory
());
if
(
module
.hot
)
{
module
.hot.accept
();
module
.hot.dispose
(()
=>
app
.
close
());
}
await
app
.
listen
(
environment
.
port
);
}
bootstrap
()
.
then
(()
=>
console
.
log
(
`
Server
started
on
port
$
{
environment
.
port
}
`
))
.
catch
(
err
=>
console
.
error
(
`
Server
startup
failed
`
,
err
));
Let’s step through this function line by line.
if
(
environment
.
production
)
{
enableProdMode
();
}
This tells the application...