Tuesday, 1 September 2020

How to setup express API and Angular Routing separately? Help ASAP!!

What's up!So, I'm working on a freelance and using Angular to develop my SPA and stuff, but the application needs a very basic email sending service, this led me to the Nodemailer and NodeJS in general.I hired the Umbler platform to host a NodeJS server and managed to point the routes on the file just like this:app.get('/', function (req, res) { res.sendFile(path.join(__dirname, '../dist', 'primierlog', 'index.html')) }) app.get('/*', function (req, res) { res.sendFile(path.join(__dirname, '../dist', 'primierlog', 'index.html')) }) app.get('/send', (req, res) => { //my email logic } So, the terrible part is that, the only way I get the /send to work is by disabling the previous /* wildcard, and by doing this i literally can't acess my SPA pages via URL+Enter. It will give me a "Cannot GET /page" which is super expected in Node. So this is the point, how the hell can I keep both API endpoints and SPA URL.If I keep the /* wildcard, basically my whole HTML with an Angular error will return (since there is NOT a /send configured as a route [which is correct because I just want to consume the API on this URL]).Anyone to help? I'm desperate!!Thanks

Submitted September 01, 2020 at 07:32PM by WilliamBenseny

No comments:

Post a Comment