'HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: 'OK', url: 'http://localhost:3000/', ok: false, …}

I was following https://blog.devgenius.io/deploy-angular-nodejs-application-to-aws-elastic-beanstalk-9ab13076a736 to deploy Angular Node Js app to AWS Beanstalk .So initially when json data is passed to localhost 3000 and that is being accessed by angular app on localhost 4200 the server was working fine without any error but when I build the Angular App and pasted the build folder to Node App view folder and added the following code:

app.use(express.static(__dirname.replace(/\\/g, "/") + '/view/dist')) 

the following error started to happen:

{
    "headers": {
        "normalizedNames": {},
        "lazyUpdate": null
    },
    "status": 200,
    "statusText": "OK",
    "url": "http://localhost:3000/",
    "ok": false,
    "name": "HttpErrorResponse",
    "message": "Http failure during parsing for http://localhost:3000/",
    "error": {
        "error": {},
        "text": "<!DOCTYPE html><html lang=\"en\"><head>\n  <meta charset=\"utf-8\">\n  <title>Angularapp</title>\n  <base href=\"/\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <script src=\"\\assets\\environment\\env.js\"></script>\n  \n<link rel=\"stylesheet\" href=\"styles.ef46db3751d8e999.css\"></head>\n<body>\n  <app-root></app-root>\n<script src=\"runtime.816becf396788283.js\" type=\"module\"></script><script src=\"polyfills.f7d1da9eeacf9a28.js\" type=\"module\"></script><script src=\"main.665e40992c2a00ab.js\" type=\"module\"></script>\n\n</body></html>"
    }
}

Than I tried to replace the code

app.use(express.static(__dirname.replace(/\\/g, "/") + '/view/dist')) 

with:

app.use(express.static(path.join(__dirname, '/view/dist')));

I got same error ...

But when I changed it to

app.use(express.static(__dirname.replace(/\\/g, "/") + '\view\dist')) 

Port 4200 and 3000 are working correctly but not showing same content which is expected once the build folder is pasted into view folder

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source