I am kinda stuck here. I am coding a webapp with Angular 4 on the client side and a REST API with Node/Express/Mongo on the server side, with an authentification with Auth0 API.
On the server side, I serve static files and all routes to Angular like that :
const distDir = __dirname + "/dist/";
app.use(express.static(distDir));
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
Without the app.get method that serves all the Angular app, I get a 404 error (cannot GET /callback for example).
The problem is that sendFile sends a html file, whatever the call is. In my app, the first calls are for js files, as seen in the Network tab (auth0.min.js). So I get this error :
ERROR SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at e.CPp0.t.json (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.project (main.0e8acae237e497f792ab.bundle.js:1)
at e._next (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.T14+.e.next (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at XMLHttpRequest.s (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.invokeTask (polyfills.043084ca495430fc14f3.bundle.js:1)
at Object.onInvokeTask (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.invokeTask (polyfills.043084ca495430fc14f3.bundle.js:1)
at r.runTask (polyfills.043084ca495430fc14f3.bundle.js:1)
I guess the authentification needs to parse some json file but the method sendFile sends HTML. I cannot get through this issue. Can someone help me ?