Skip to content

Using Angular , React , VueJS #1818

Description

@mightytyphoon

Description / Feature proposal

Serving a web application with built-in router in 3 ways :

  • Serving the Web app from the loopback public folder and let the web application handles routes while cohabiting with http REST requests from the web application and websockets if needed.
  • Serving the Web app from a CDN while the loopback server handles its requests (should already work I think)
  • Serving the Web app with a server side rendering such as Angular Universal

Later it could be interesting to handle the rendering on CDNs or to use also CDNs for loopback requests. The goal is to have a high performance delivery service for the user.

Current Behavior

Does not propose a default way to use a routed App such as Angular, React, Vuejs leading to 404 errors.

Expected Behavior

  • Having some documentation on managing web apps with built in router (Angular, React, VueJS)
  • Propose a default configuration in the CLI to handle automatically the needed changes.
  • Propose to reverse the configuration in case of error (later)

Some tries of mine

I will speak for Angular first even if I think VueJS and React should be really close in the use.

In loopback 3 there was a need to change the middleware and let the angular app handle routes, so if your web application was in a public folder you would need to serve index.html and redirect every routes to the index.html to let Angular deal with these routes.
Here is a post on how to do it : stackoverflow - configure loopback 3 to serve Angular 4+

Now get back to loopback 4.
I think the file to change to let the web app deal with routes is the sequence file : src/sequence.ts

If I serve the dist folder of a fresh Angular in the public folder I will have some 404 errors from Angular in browser console :

GET http://localhost:3000/runtime.js net::ERR_ABORTED 404 (Not Found)
5Refused to execute script from '<URL>' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:3000/runtime.js' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:3000/polyfills.js' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:3000/styles.js' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:3000/vendor.js' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to execute script from 'http://localhost:3000/main.js' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
4localhost/:13 GET http://localhost:3000/polyfills.js net::ERR_ABORTED 404 (Not Found)

For now I am trying to play with the sequence.ts file to re-send http routes in browser to the angular app like in loopback 3, any help would be appreciated.

Regards.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions