Search code examples
node.jsangularheroku

routes in angular and nodejs deployed app not working


I have deloyed a nodejs and angular app on heroku but after deployed routes are not working. here is my webiste - https://murti123.herokuapp.com with routes - enter link description here

but with routes it gives a can't get / errror. i don't know how to resolve it

Here is My project Structureenter code here


Solution

  • You need to resolve your path to the frontend application

    so assume that in /public folder you have the dist files from the builded frontend application

    app.use(express.static(__dirname + "/public"));
    

    and here you resolve that index.html for any route

    app.get("*", function (req, res) {
      //path is required at the top of the file ofcourse
      //const path = require("path"); 
      res.status(200).sendFile(path.resolve(__dirname + "/public/index.html"));
    });