How to route api and website files? #8450
-
In LB3 you could mount a website and the backing api like this: http://1.2.3.4/ <- WEBSITE This is achieved with a simple LB3 config:
I seem to be missing some simple solution? In LB4 I've tried to:
This api decorator causes a secondary problem, where a SPA frontend app (Angular, React, etc) needs to handle routing not related to the /api paths, on the client side. To make this work is a bit hacky IMO. In the application sequence I have to bypass authentication except for api routes, and then return control to the frontend app on 404 errors, like this:
The documentation appears to suggest creating separate servers/applications for each base route, and then running them on different ports and with their own configs and individual sequences. That just seems wrong. The example applications side step the issue by just not using the same path names to avoid collision between frontend and backend of the same name. For instance, in the shopping example, the frontend api path is defined as What is the recommended way to achieve this common scenario? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
So I guess the solution is to make your whole Loopback application simply a route of a parent express app like this:
To do this, make sure you prevent your loopback application from starting and listening to it's own http server by adding The steps are detailed here. This solves a couple other issues too:
|
Beta Was this translation helpful? Give feedback.
So I guess the solution is to make your whole Loopback application simply a route of a parent express app like this:
To do this, make sure you prevent your loopback application from starting and listening to it's own http server by adding
listenOnStart: false
to the options in index.ts.The steps are detailed here.
https://loopback.io/doc/en/lb4/express-…