Skip to content

How to route api and website files? #8450

Discussion options

You must be logged in to vote

So I guess the solution is to make your whole Loopback application simply a route of a parent express app like this:

    this.app = express();
    this.httpServer = createServer(this.app);

    this.lbApp = new Lb4Application(options);
    this.app.use('/api', this.lbApp.requestHandler);  //   <-- loopback assigned to /api route

    // frontend files now at root!
    this.app.use('/', express.static(path.join(__dirname, '../path/to/frontend/files'))) 

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-…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Bahlinc-Dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant