Introduce static resource URLs
Summary: Introduced an API that converts a filepath, relatively to the `desktop/static/` folder in a url that can be resolved by the render environment. This will generate `file://` urls in Electron, and root relative `/` urls in browser envs Reviewed By: aigoncharov Differential Revision: D32767427 fbshipit-source-id: 378da7709bcb19449873358a8703b9c5a5809c57
This commit is contained in:
committed by
Facebook GitHub Bot
parent
129cbd6f7b
commit
86995e0d11
@@ -180,6 +180,12 @@ export function initializeElectron(
|
|||||||
async requirePlugin(path) {
|
async requirePlugin(path) {
|
||||||
return (window as any).electronRequire(path);
|
return (window as any).electronRequire(path);
|
||||||
},
|
},
|
||||||
|
getStaticResourceUrl(relativePath): string {
|
||||||
|
return (
|
||||||
|
'file://' +
|
||||||
|
path.resolve(flipperServerConfig.paths.staticPath, relativePath)
|
||||||
|
);
|
||||||
|
},
|
||||||
} as RenderHost;
|
} as RenderHost;
|
||||||
|
|
||||||
setupMenuBar();
|
setupMenuBar();
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ export function initializeRenderHost(
|
|||||||
// eslint-disable-next-line no-eval
|
// eslint-disable-next-line no-eval
|
||||||
return eval(source);
|
return eval(source);
|
||||||
},
|
},
|
||||||
|
getStaticResourceUrl(path): string {
|
||||||
|
// the 'static' folder is mounted as static middleware in Express at the root
|
||||||
|
return '/' + path;
|
||||||
|
},
|
||||||
} as RenderHost;
|
} as RenderHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ export interface RenderHost {
|
|||||||
flipperServer: FlipperServer;
|
flipperServer: FlipperServer;
|
||||||
serverConfig: FlipperServerConfig;
|
serverConfig: FlipperServerConfig;
|
||||||
requirePlugin(path: string): Promise<any>;
|
requirePlugin(path: string): Promise<any>;
|
||||||
|
getStaticResourceUrl(relativePath: string): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRenderHostInstance(): RenderHost {
|
export function getRenderHostInstance(): RenderHost {
|
||||||
|
|||||||
@@ -187,5 +187,8 @@ function createStubRenderHost(): RenderHost {
|
|||||||
async requirePlugin(path: string) {
|
async requirePlugin(path: string) {
|
||||||
return require(path);
|
return require(path);
|
||||||
},
|
},
|
||||||
|
getStaticResourceUrl(relativePath): string {
|
||||||
|
return 'file://' + resolve(rootPath, 'static', relativePath);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user