mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 06:59:26 +08:00
fix: ensure URL paths start with public path and redirect public path without trailing slash
This commit is contained in:
parent
fa60e339b4
commit
5ecd48ad15
@ -36,7 +36,7 @@ export default defineConfig({
|
|||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
src: `${appPublicPath}browser-checker.js`,
|
src: `${appPublicPath}browser-checker.js?v=1`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
cacheDirectoryPath: process.env.APP_CLIENT_CACHE_DIR || `node_modules/.cache`,
|
cacheDirectoryPath: process.env.APP_CLIENT_CACHE_DIR || `node_modules/.cache`,
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
const basename = window['__nocobase_public_path__'] || '/';
|
const basename = window['__nocobase_public_path__'] || '/';
|
||||||
let currentPath = window.location.pathname;
|
let currentPath = window.location.pathname;
|
||||||
if (!currentPath.startsWith(basename)) {
|
if (currentPath === basename.slice(0, -1)) {
|
||||||
|
const newUrl = `${window.location.origin}${basename}${window.location.search}${window.location.hash}`;
|
||||||
|
window.location.replace(newUrl);
|
||||||
|
} else if (!currentPath.startsWith(basename)) {
|
||||||
let newPath = basename + (currentPath.startsWith('/') ? currentPath.slice(1) : currentPath);
|
let newPath = basename + (currentPath.startsWith('/') ? currentPath.slice(1) : currentPath);
|
||||||
let newUrl = window.location.origin + newPath + window.location.search + window.location.hash;
|
let newUrl = window.location.origin + newPath + window.location.search + window.location.hash;
|
||||||
window.location.href = newUrl;
|
window.location.replace(newUrl);
|
||||||
}
|
}
|
||||||
showLog = true;
|
showLog = true;
|
||||||
function log(m) {
|
function log(m) {
|
||||||
|
@ -65,6 +65,8 @@ server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{otherLocation}}
|
||||||
|
|
||||||
location ^~ {{publicPath}}api/ {
|
location ^~ {{publicPath}}api/ {
|
||||||
proxy_pass http://127.0.0.1:{{apiPort}};
|
proxy_pass http://127.0.0.1:{{apiPort}};
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
@ -19,11 +19,18 @@ module.exports = (cli) => {
|
|||||||
cli.command('create-nginx-conf').action(async (name, options) => {
|
cli.command('create-nginx-conf').action(async (name, options) => {
|
||||||
const file = resolve(__dirname, '../../nocobase.conf.tpl');
|
const file = resolve(__dirname, '../../nocobase.conf.tpl');
|
||||||
const data = readFileSync(file, 'utf-8');
|
const data = readFileSync(file, 'utf-8');
|
||||||
|
let otherLocation = '';
|
||||||
|
if (process.env.APP_PUBLIC_PATH !== '/') {
|
||||||
|
otherLocation = `location / {
|
||||||
|
alias {{cwd}}/node_modules/@nocobase/app/dist/client/;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}`;
|
||||||
|
}
|
||||||
const replaced = data
|
const replaced = data
|
||||||
.replace(/\{\{cwd\}\}/g, '/app/nocobase')
|
.replace(/\{\{cwd\}\}/g, '/app/nocobase')
|
||||||
.replace(/\{\{publicPath\}\}/g, process.env.APP_PUBLIC_PATH)
|
.replace(/\{\{publicPath\}\}/g, process.env.APP_PUBLIC_PATH)
|
||||||
.replace(/\{\{apiPort\}\}/g, process.env.APP_PORT);
|
.replace(/\{\{apiPort\}\}/g, process.env.APP_PORT)
|
||||||
|
.replace(/\{\{otherLocation\}\}/g, otherLocation);
|
||||||
const targetFile = resolve(process.cwd(), 'storage', 'nocobase.conf');
|
const targetFile = resolve(process.cwd(), 'storage', 'nocobase.conf');
|
||||||
writeFileSync(targetFile, replaced);
|
writeFileSync(targetFile, replaced);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user