Reputation: 36620
I have question that came to mind about an Angular project for which I cannot find a satisfying answer. When I googled for it I only came up with how to deploy the application and not an answer which answered my specific question.
Normally when an angular application is developed we can run ng serve
in order to get a development server. When we then visit the dev
server we get served the following files which are required for the SPA.
The development server serves our only static HTML
asset the index.html file and the necessary bundles of compiled angular code on which our application runs.
When we deploy an Angular application is the Angular application still in need of a server on which serves the application? Or can we just serve this bundle of files from our backend?
Upvotes: 2
Views: 132
Reputation: 2192
You need to generate your application files with $ ng build
command. The build artifacts will be stored in the dist/ directory. Then you can use a service like Surge as a static web publishing or other webserver.
On the other hand, if your application use Angular Router, what I said above will not work wonderfully. You need to add a middleware.
If you're using Express for example you need to add something like this:
// server.js
const path = require('path');
app.get('/*all', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
Hope I help!
Upvotes: 2