I give a try to the Angular's Server Side Rendering and getting stuck to the simplest use case I imagined.
Test 1
Test 2
Way to reproduce
ng new --ssr
(by runing this, I consider that express server will be well configured by default)server.get('*', (req, res, next) => { /* content */ });
content (Angular app) by res.send({msg: "welcome"});
ng serve
curl http://localhost:4200
I'm getting default Angular homepage, but I expected to receive the {msg: "welcome"} objectng serve
again server.get('/toto', async (req, res) => {
res.send({msg: "toto"})
});
curl http://localhost:4200/toto
The Angular Router answers me, not ExpressFrom these two tests, it seems that express impl from server.ts is completely skipped.
I probably missed something obvious but Angular doc, Express doc or just googling don't give me any clue...
In angular.json, the server.ts is correctly specified projects.latest-ng.architect.build.options.ssr.entry: "server.ts"
, there's no compilation issue.
Does anyone have any idea what's wrong?
ng serve doesn't use server.ts (it doesn't use express.) You have to build your app with production configuration and run your created server.mjs file with node. With this way your application will use server.te file.