Skip to content

Commit

Permalink
fix: Move to absolute paths as relative paths cause problems on html …
Browse files Browse the repository at this point in the history
…pages which are served in subpaths

e.g. '/user/index.html' still served 'assets/index.js' instead of '/assets/index.js'
this would only be working in combination with the '<base>' html tag.
By introducing the absolute paths, the web application won't work anymore
when it's served through a proxy.

Maybe I will re-introduce relative paths that are generated on demand, so we don't
need a specific base.

Support for a 'X-CDN-URL' header might also be interesting.
  • Loading branch information
marcbachmann committed Aug 30, 2019
1 parent c7be8e7 commit 57ff2b6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function webpackPlugin (fastify, options) {
// support a prefix `/` which would result in `///assets`
// we can't use path.join here because we want to be cross-platform compatible
// and this is a url, not a file system path
const publicPath = `/${options.prefix}/assets`.replace(/\/\/\/?/g, '/')
const publicPath = `/${options.prefix}/assets`.replace(/\/+/g, '/')

let assetsMap
if (!options.watch) {
Expand Down Expand Up @@ -84,7 +84,7 @@ async function webpackPlugin (fastify, options) {
})

const publicAssetPath = (pathname) => {
if (!options.cdnUrl) return pathname
if (!options.cdnUrl) return publicPath.replace(/assets$/, pathname)
// make sure that the cdnUrl has always a postfix `/`
return `${options.cdnUrl.replace(/\/?$/, '/') || ''}${pathname.replace('assets/', '')}`
}
Expand Down

0 comments on commit 57ff2b6

Please sign in to comment.