Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Configuring historyApiFallback when using multiple entry points #1274

Closed
helfi92 opened this issue Dec 31, 2018 · 5 comments
Closed

Configuring historyApiFallback when using multiple entry points #1274

helfi92 opened this issue Dec 31, 2018 · 5 comments

Comments

@helfi92
Copy link
Member

helfi92 commented Dec 31, 2018

Bug? Issue?

  • What version of Neutrino are you using?

9.0.0-rc.0

  • Are you using the Yarn client or the npm client? What version?

yarn v1.12.3

  • What version of Node.js are you using?

10.0.0

  • What operating system are you using?

macOS High Sierra

  • What did you do?

I'm trying to have the /docs path of the site point to a separate entry point and everything else to the main index entry. In other words, I am trying to operate 2 SPA in the same site. This will be useful for us when we decide not to show a part of the application (e.g., only ship the docs).

I modified the mains options in .neutrinorc.js and added a rewrite:

Added a docs entry point

+  options: {
+    mains: {
+      index: 'index.jsx',
+      docs: 'docs.jsx',
+    },
+  },

Whenever the user navigates to a url that starts with /docs, navigate the user to the second entry point

-        historyApiFallback: { disableDotRule: true },
+        historyApiFallback: {
+          disableDotRule: true,
+          rewrites: [
+            { from: /^\/docs/, to: 'docs.html' },
+          ],
+        },
  • What did you expect to happen?

The docs view is loaded

  • What actually happened, contrary to your expectations?

The browser throws Cannot GET /docs when I type http://localhost:5080/docs in the url bar and press enter. Here's the branch with the changes: taskcluster/taskcluster-web#342. Thank you.

@edmorley
Copy link
Member

edmorley commented Jan 4, 2019

Neutrino 9 already supports multiple entrypoints via the mains option (we use this feature in Treeherder) - however it currently uses the basic historyApiFallback defaults when there are multiple entrypoints. Once we have a working config for you for this case, we should decide whether to make it do so automatically, or document/disable the historyApiFallback feature if using multiple entry-points.

Looking at the upstream implementation:
https://github.com/webpack/webpack-dev-server/blob/v3.1.14/lib/Server.js#L387-L395
https://github.com/bripkens/connect-history-api-fallback/blob/v1.5.0/lib/index.js#L52-L54

...it seems that the provided URL is used directly and not normalised - so perhaps the leading / is mandatory? Could you try using to: '/docs.html' rather than to: 'docs.html' and see if that works?

If that works, it would be good to file an issue against connect-history-api-fallback to make it either error if the leading slash is missing, or else automatically normalise the URL.

Failing that, connect-history-api-fallback has a verbose option which will mean additional debug information is output - which I'd recommend trying:
https://github.com/bripkens/connect-history-api-fallback/tree/v1.5.0#verbose

@edmorley edmorley changed the title Multiple SPAs? Configuring historyApiFallback when using multiple entry points Jan 4, 2019
@helfi92
Copy link
Member Author

helfi92 commented Jan 4, 2019

Could you try using to: '/docs.html' rather than to: 'docs.html' and see if that works?

Wow, that did it. You're the best @edmorley! Thank you.

@helfi92 helfi92 closed this as completed Jan 4, 2019
@edmorley
Copy link
Member

If that works, it would be good to file an issue against connect-history-api-fallback to make it either error if the leading slash is missing, or else automatically normalise the URL.

@helfi92 I don't suppose you had a chance to do this ^? :-)

@helfi92
Copy link
Member Author

helfi92 commented Mar 25, 2019

This was done in bripkens/connect-history-api-fallback@e931cce :)

@edmorley
Copy link
Member

Oh awesome, thank you :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants