app-backend,cli: move backstage-app-mode injection to build time
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -218,7 +218,6 @@ export async function createRouter(
|
||||
|
||||
publicRouter.use(
|
||||
await createEntryPointRouter({
|
||||
appMode: 'public',
|
||||
logger: logger.child({ entry: 'public' }),
|
||||
rootDir: publicDistDir,
|
||||
assetStore: assetStore?.withNamespace('public'),
|
||||
@@ -231,7 +230,6 @@ export async function createRouter(
|
||||
|
||||
router.use(
|
||||
await createEntryPointRouter({
|
||||
appMode: enablePublicEntryPoint ? 'protected' : 'public',
|
||||
logger: logger.child({ entry: 'main' }),
|
||||
rootDir: appDistDir,
|
||||
assetStore,
|
||||
@@ -243,41 +241,17 @@ export async function createRouter(
|
||||
return router;
|
||||
}
|
||||
|
||||
async function injectAppMode(options: {
|
||||
appMode: 'public' | 'protected';
|
||||
rootDir: string;
|
||||
}) {
|
||||
const { appMode, rootDir } = options;
|
||||
const content = await fs.readFile(resolvePath(rootDir, 'index.html'), 'utf8');
|
||||
|
||||
const metaTag = `<meta name="backstage-app-mode" content="${appMode}">`;
|
||||
|
||||
let newContent;
|
||||
if (content.includes('backstage-app-mode')) {
|
||||
newContent = content.replace(
|
||||
/<meta name="backstage-app-mode" content="[^"]+">/,
|
||||
metaTag,
|
||||
);
|
||||
} else {
|
||||
newContent = content.replace(/<head>/, `<head>${metaTag}`);
|
||||
}
|
||||
|
||||
await fs.writeFile(resolvePath(rootDir, 'index.html'), newContent, 'utf8');
|
||||
}
|
||||
|
||||
async function createEntryPointRouter({
|
||||
logger,
|
||||
rootDir,
|
||||
assetStore,
|
||||
staticFallbackHandler,
|
||||
appMode,
|
||||
appConfigs,
|
||||
}: {
|
||||
logger: LoggerService;
|
||||
rootDir: string;
|
||||
assetStore?: StaticAssetsStore;
|
||||
staticFallbackHandler?: express.Handler;
|
||||
appMode: 'public' | 'protected';
|
||||
appConfigs?: AppConfig[];
|
||||
}) {
|
||||
const staticDir = resolvePath(rootDir, 'static');
|
||||
@@ -285,8 +259,6 @@ async function createEntryPointRouter({
|
||||
const injectedConfigPath =
|
||||
appConfigs && (await injectConfig({ appConfigs, logger, staticDir }));
|
||||
|
||||
await injectAppMode({ appMode, rootDir });
|
||||
|
||||
const router = Router();
|
||||
|
||||
// Use a separate router for static content so that a fallback can be provided by backend
|
||||
|
||||
Reference in New Issue
Block a user