Skip to content

Commit

Permalink
fixup! feat(core): add viaProxy Utility to rewrite requests to proxy (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
WaldemarLehner committed Feb 19, 2023
1 parent fee851e commit 5380bfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions packages/vite-plugin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ export interface MotionCanvasPluginConfig {
*
* @remarks
* This passes configuration to Motion Canvas' proxy.
* Not setting this value will allow all `image/*` and `video/*` resources from any hostname.
* You can also disable the proxy entirely by passing `false`. This will however mean that you
* cannot render any animation that relies on remote sources.
*/
* Note that the proxy is disabled by default.
* You can either pass `true` and a config object
* to enable it.
**/
proxy?: boolean | MotionCanvasCorsProxyOptions;
}

Expand Down Expand Up @@ -332,12 +332,11 @@ export default ({
next();
});

// This is intentionally !== false as undefined should be allowed
if (proxy !== false) {
motionCanvasCorsProxy(
server.middlewares,
proxy === true ? undefined : proxy,
);
// if proxy is unset (undefined), or set to false,
// it will not register its middleware — as a result, no
// proxy is started.
if (proxy !== false && proxy !== undefined) {
motionCanvasCorsProxy(server.middlewares, proxy === true ? {} : proxy);
}

server.ws.on('motion-canvas:meta', async ({source, data}, client) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin/src/proxy-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function setupEnvVarsForProxy(
const isEnabledKey = prefix + 'ENABLED';
const allowList = prefix + 'ALLOW_LIST';

if (config === true || config === undefined) {
if (config === true) {
config = {}; // Use Default values
}

Expand All @@ -69,7 +69,7 @@ export function setupEnvVarsForProxy(

export function motionCanvasCorsProxy(
middleware: Connect.Server,
config: MotionCanvasCorsProxyOptions | undefined = {},
config: MotionCanvasCorsProxyOptions,
) {
// Set the default config if no config was provided
config.allowedMimeTypes ??= ['image/*', 'video/*'];
Expand Down

0 comments on commit 5380bfe

Please sign in to comment.