Skip to content

Make dev-server work with assetsPublicPath #915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

grakic
Copy link

@grakic grakic commented Sep 9, 2017

If assetsPublicPath is set in configuration options, dev-server should use it as path to index.html

If assetsPublicPath is set in configuration options, dev-server should use it as path to index.html
@jdhartley
Copy link

This fixes a bug I was running into, where the dev server was returning

Cannot GET /assetsPublicPath/

(where assetsPublicPath is the directory)

Thanks!

@LinusBorg
Copy link
Contributor

LinusBorg commented Oct 3, 2017

Hi @grakic

Can you elaborate a bit about what situations and problems this prevents? I'm not entirely sure I see the problem this is fixing.

@grakic
Copy link
Author

grakic commented Oct 4, 2017

Hi,

In the config/index.js there is this assetsPublicPath configuration option. By default it is set to a root path. I am working on the application that is deployed to a sub-directory, so in my project I set assetsPublicPath to /panel/.

The middleware connect-history-api-fallback is responsible for routing requests to the main /index.html file. You can read more here. Because of assetsPublicPath my main index.html file is not served as localhost:5000/index.html but instead it is served as localhost:5000/panel/index.html.

Without this change, when I access localhost:5000/panel/ the request is not rewritten to index.html and I get the error "Cannot GET /panel/". Configuring connect-history-api-fallback with the correct index path is fixing this problem.

For convenience this change also adds a redirect from / to /panel (or whatever is set as assetsPublicPath). You can now run the server and access localhost:5000 which would then redirect to the app hosted at localhost:5000/panel/ which shows the index.html content.

Nothing is changed if assetsPublicPath is left at the default value. In that case no redirect is added and connect-history-api-fallback will be configured with /index.html which is the default setting.

@LinusBorg
Copy link
Contributor

@grakic We will be switching to webpack-dev-server (see #975).

I will leave this PR open, but set a "request changes" block.

I would ask you to test this issue with webpack-dev-server (you can check the PR's branch out and test it locally, see #975, or after we officially merged it) and either close this PR if the issue doesn't persist, or adjust this PR to apply to the new setup.

Copy link
Contributor

@LinusBorg LinusBorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

@grakic grakic closed this Oct 12, 2017
@grakic grakic deleted the patch-1 branch October 12, 2017 17:31
@grakic grakic restored the patch-1 branch October 12, 2017 17:41
@grakic
Copy link
Author

grakic commented Oct 12, 2017

Hi @LinusBorg I can confirm that there are no issues with webpack-dev-server now. Only redirect is missing, I've pushed this as #980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants