I have upload my angular production build on live. And I'm missing some thing but I don't know what is that.
In build/index.html
I have set this in base URL.
<base href="http://0.0.0.0:3000/admin/"> // Instead of 0.0.0.0 I have set my EC2 instance's elastic ip address
I have set /var/www/html/myapp/admin
. Hear in admin folder angular build is that.
And my node server is at /var/www/html/app.js
app.js
To allow all admin panel pages I have add this code in my app.js file.
app.use('/', express.static('./admin'))
app.get('*', (req, res) => {
res.sendfile('./admin/index.html')
})
When you use app.use('/', express.static('./admin'))
, the static files will be served in the root directory, for example, http://0.0.0.0:3000/main.js, but because of the base
tag, it will try to find the resource at http://0.0.0.0:3000/admin/main.js.
To fix it, change the path of the static files, like so:
app.use('/admin', express.static('./admin'));
Also, I don't recommend editing the base
tag manually, you can set the base url in the build command, like so:
ng build --prod --base-href="http://0.0.0.0:3000/admin/"