in [project-root]/server.ts, I wanted to add one extra express route… for now, I added these lines:
import bodyParser from 'body-parser';
import {handleFoo} from "./foo-handler";
and
server.post('/api/foo', jsonParser, (req, res) => {
try {
handleFoo(req.body);
res.send(`{ "result": "success"}`);
} catch(error) {
res.status(500).send(`{ "result": "fail"}`);
}
});
I didn’t want to put foo-handler.ts in src, since I ain’t quite sure of the webpack/optimization split between browser and server side code … so I just stuck in in [project-root]/
It works, and it’s good enough for this week… but I was wondering what is common practice for this?
Does one move everything in [project-root]/src/ into [project-root]/src/browser, and then move [project-root]/foo-handler.ts into [project-root]/server/foo-handler.ts?
Would this require much in the way of angular.json changes?
In a related note…. is it considered a bad separation of concerns to add server side express routes to angular ssr apps? At what point do you decide…. nah, lets spin up a separate microservice?
(For this deployment, it’s one and done…. but the incident had me wondering what is
best practice)