Clean up App base url replacement (#9192)

This commit is contained in:
Nicola Krumschmidt
2021-10-27 18:33:26 +02:00
committed by GitHub
parent 63ea5328ec
commit 2934b6ca76
2 changed files with 5 additions and 7 deletions

View File

@@ -132,16 +132,13 @@ export default async function createApp(): Promise<express.Application> {
const adminUrl = new Url(env.PUBLIC_URL).addPath('admin');
// Set the App's base path according to the APIs public URL
let html = fse.readFileSync(adminPath, 'utf-8');
html = html.replace(
/<meta charset="utf-8" \/>/,
`<meta charset="utf-8" />\n\t\t<base href="${adminUrl.toString({ rootRelative: true })}/">`
);
const html = await fse.readFile(adminPath, 'utf8');
const htmlWithBase = html.replace(/<base \/>/, `<base href="${adminUrl.toString({ rootRelative: true })}/" />`);
app.get('/admin', (req, res) => res.send(html));
app.get('/admin', (req, res) => res.send(htmlWithBase));
app.use('/admin', express.static(path.join(adminPath, '..')));
app.use('/admin/*', (req, res) => {
res.send(html);
res.send(htmlWithBase);
});
}