Home Serve Angular App and its API using Express
Reply: 0

Serve Angular App and its API using Express

user1471 Published in June 18, 2018, 7:38 am

I have an Express app set up with has this routing configuration:

app.use(express.static(path.join(__dirname, '../angular-app/dist')));
  express.Router().get('/', function(req, res, next) {
app.use('/v1', v1); // these are my API routes

If I launch this express app and navigate (in a browser) to its root, the Angular app comes up, but if I navigate to any of the routes within the Angular app, e.g. /mycomponent/ I get the 404 route rendering from Express.

What I want to have happen is that any route that doesn't start with /v1 is delegated to the angular app, and otherwise my API is served. Is this not a sound way of thinking about how to deploy this pair of applications?

To compound this, I have this hosted on an Apache server using a reverse proxy configuration.

   <Location /myapp>
      ProxyPassReverse http://1127.0.0.1:3000

... and of course my angular app has <base href="/myapp/"/> in its index.html template to support this. So I'm wondering if the only way to do this "correctly" is to use the reverse proxy for the Express app and have it only serve the API routes, then use some kind of mod_rewrite configuration in Apache to host the Angular app directly from Apache. What do you think?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.342158 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO