Skip to content
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

Support publicPath in vue.config.js #98

Merged
merged 5 commits into from
Oct 20, 2019
Merged

Support publicPath in vue.config.js #98

merged 5 commits into from
Oct 20, 2019

Conversation

ulich
Copy link
Contributor

@ulich ulich commented Apr 17, 2019

Fixes #97

if publicPath is set in vue.config.js in order to host the application under a path prefix, the router on the server side didn't find a matching route
@dennisreimann
Copy link

dennisreimann commented Jun 13, 2019

Some minor additions:

Implementing prepareUrlForRouting like this and moving it below the import statement in entry-server.js would better fit the coding style of this project and also ensure that the base url works without the trailing slash:

const prepareUrlForRouting = url => {
  const { BASE_URL } = process.env
  return url.startsWith(BASE_URL.replace(/\/$/, ''))
    ? url.substr(BASE_URL.length)
    : url
}

We could also change this line in dev-server.js to point to the correct entry url of the app:

const url = `http://localhost:${config.port}${service.projectOptions.publicPath}`

When testing this, I found the changes in 2e729de to not be necessary to make the publicPath option work with this plugin. I might be missing something, as the app I'm trying it out with is not very big yet. In case this is necessary I think we should also prepend the publicPath in this line like that:

app.get(`${publicPath}*`, (req, res, next) => {
  if (config.skipRequests(req)) {
    return next()
  }
  ssr(req, res)
})

@ulich
Copy link
Contributor Author

ulich commented Jun 13, 2019

I will adapt my PR with your remarks.

About:

When testing this, I found the changes in 2e729de to not be necessary to make the publicPath option work with this plugin.

This only happens when running the production build. The requests to download the javascript bundle all return the html content of the page instead of the static files.

@dennisreimann
Copy link

I have this PR running in our project and tested it to the extend of our needs. AFAIK this seems good to go 👍

@dennisreimann
Copy link

fyi: While we are waiting for this to get merged I've published a fork on npm, which includes this and other PRs.

Looking forward to seeing this merged!

@Akryum Akryum merged commit 9162257 into Akryum:master Oct 20, 2019
@Akryum
Copy link
Owner

Akryum commented Oct 20, 2019

👍

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

Successfully merging this pull request may close these issues.

Support publicPath in vue.config.js
3 participants