Merge pull request #827 from maartenvn/fix/publicurl

Fix inconsistent PUBLIC_URL (#826)
This commit is contained in:
Rijk van Zanten
2020-10-31 14:11:16 +01:00
committed by GitHub

View File

@@ -82,13 +82,14 @@ export default async function createApp() {
if (env.NODE_ENV !== 'development') {
const adminPath = require.resolve('@directus/app/dist/index.html');
const publicUrl = env.PUBLIC_URL.endsWith('/') ? env.PUBLIC_URL : env.PUBLIC_URL + '/';
// Prefix all href/src in the index html with the APIs public path
let html = fse.readFileSync(adminPath, 'utf-8');
html = html.replace(/href="\//g, `href="${env.PUBLIC_URL}`);
html = html.replace(/src="\//g, `src="${env.PUBLIC_URL}`);
html = html.replace(/href="\//g, `href="${publicUrl}`);
html = html.replace(/src="\//g, `src="${publicUrl}`);
app.get('/', (req, res) => res.redirect(`${env.PUBLIC_URL}admin/`));
app.get('/', (req, res) => res.redirect(`./admin/`));
app.get('/admin', (req, res) => res.send(html));
app.use('/admin', express.static(path.join(adminPath, '..')));
app.use('/admin/*', (req, res) => {