Permalink
Browse files

fix: prevent invalid url when router base is /

  • Loading branch information...
pi0 committed Jun 4, 2017
1 parent 3b135cc commit f0fd8636c51a84fc0102ac0358639711ee67ff42
Showing with 7 additions and 5 deletions.
  1. +6 −4 modules/manifest/index.js
  2. +1 −1 modules/workbox/index.js
@@ -6,7 +6,7 @@ const hash = require('hash-sum')
const fixUrl = url => url.replace(/(?!^)\/\//g, '/').replace(':/', '://')// // ~> /
module.exports = function nuxtManifest(options) {
const routerBase = this.options.router.base
const routerBase = this.options.router.base === '/' ? '' : this.options.router.base
const defaultName = options.name || this.options.manifest.name || process.env.npm_package_name
const defaultShortName = process.env.npm_package_name || defaultName
@@ -16,12 +16,12 @@ module.exports = function nuxtManifest(options) {
description: defaultName,
icons: [
{
src: fixUrl(`${routerBase}icon.png`),
src: fixUrl(`${routerBase}/icon.png`),
sizes: '512x512',
type: 'image/png'
}
],
start_url: routerBase,
start_url: fixUrl(`${routerBase}/`),
display: 'standalone',
background_color: '#ffffff',
theme_color: (this.options.loading && this.options.loading.color) || '#3f51b5',
@@ -34,7 +34,9 @@ module.exports = function nuxtManifest(options) {
const manifestFileName = `manifest.${hash(manifest)}.json`
const distDir = 'static'
const manifestFilePath = path.resolve(this.options.rootDir, distDir, manifestFileName)
console.log(manifestFilePath)
// Fix problem with now deployments which start script is running on a ro environment
// We need to somehow detect module is running in build or start mode
if (!fs.existsSync(manifestFilePath)) {
fs.ensureDirSync(path.resolve(this.options.rootDir, distDir))
fs.writeFileSync(manifestFilePath, JSON.stringify(manifest), 'utf8')
@@ -12,7 +12,7 @@ module.exports = function nuxtWorkbox(options) {
}
const swFileName = 'sw.js'
const routerBase = this.options.router.base
const routerBase = this.options.router.base === '/' ? '' : this.options.router.base
const publicPath = isUrl(this.options.build.publicPath)
? this.options.build.publicPath
: fixUrl(routerBase + this.options.build.publicPath)

0 comments on commit f0fd863

Please sign in to comment.