Fixed route changes not using getUrl causing invalid url to be used when
using pathPrefix, renamed basePath to prefixPath, updated how getUrl gets the prefixPath to prevent the need for rebuilding when its changed now just requires restart
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
// make sure basePath doesn't end with /
|
||||
let { basePath } = require('../config/host.json')
|
||||
const urlChars = basePath.split('')
|
||||
|
||||
if (basePath.length > 1 && urlChars.pop() === '/') {
|
||||
basePath = urlChars.join('')
|
||||
}
|
||||
module.exports = basePath
|
||||
@@ -1,15 +1,18 @@
|
||||
const url = require('url')
|
||||
const urljoin = require('url-join')
|
||||
const basePath = require('./basePath')
|
||||
const { host, port, protocol } = require('../config/host.json')
|
||||
|
||||
module.exports = (path, absolute) => {
|
||||
path = urljoin(basePath, path)
|
||||
const { pathPrefix } =
|
||||
typeof window === 'undefined' ? app.get('kbConf') : window.kbConf
|
||||
|
||||
path = urljoin(pathPrefix, path)
|
||||
if (!absolute) return path
|
||||
|
||||
// absolute should only be used during ssr
|
||||
return url.format({
|
||||
hostname: host,
|
||||
port,
|
||||
protocol,
|
||||
hostname: app.get('host'),
|
||||
port: app.get('port'),
|
||||
pathname: path,
|
||||
protocol: 'http',
|
||||
})
|
||||
}
|
||||
|
||||
8
util/pathPrefix.js
Normal file
8
util/pathPrefix.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// make sure basePath doesn't end with /
|
||||
let { pathPrefix } = require('../config/host.json')
|
||||
const urlChars = pathPrefix.split('')
|
||||
|
||||
if (pathPrefix.length > 1 && urlChars.pop() === '/') {
|
||||
pathPrefix = urlChars.join('')
|
||||
}
|
||||
module.exports = pathPrefix
|
||||
@@ -1,8 +0,0 @@
|
||||
const basePath = require('./basePath')
|
||||
|
||||
module.exports = url => {
|
||||
if (basePath !== '/') {
|
||||
url = url.split(basePath).join('')
|
||||
}
|
||||
return url
|
||||
}
|
||||
8
util/stripPrefix.js
Normal file
8
util/stripPrefix.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const pathPrefix = require('./pathPrefix')
|
||||
|
||||
module.exports = url => {
|
||||
if (pathPrefix !== '/') {
|
||||
url = url.split(pathPrefix).join('')
|
||||
}
|
||||
return url
|
||||
}
|
||||
Reference in New Issue
Block a user