diff --git a/package-lock.json b/package-lock.json index 96c5db87..d1d21d78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gofynd/fdk-cli", - "version": "8.0.9", + "version": "8.0.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@gofynd/fdk-cli", - "version": "8.0.9", + "version": "8.0.10", "license": "MIT", "dependencies": { "@babel/core": "^7.24.9", diff --git a/package.json b/package.json index 0ba32600..a51c50b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gofynd/fdk-cli", - "version": "8.0.9", + "version": "8.0.10", "main": "index.js", "license": "MIT", "bin": { diff --git a/src/helper/serve.utils.ts b/src/helper/serve.utils.ts index 539ca2b3..add3e89f 100644 --- a/src/helper/serve.utils.ts +++ b/src/helper/serve.utils.ts @@ -36,10 +36,16 @@ const SERVE_BUILD_FOLDER = './.fdk/distServed'; let port = 5001; let sockets = []; let publicCache = {}; +// Identifies the request as originating from the CLI. Kept separate from +// `headers` so it can be attached to non-JSON requests (static assets, proxied +// traffic) without forcing a JSON Content-Type/Accept on them. +const cliHeaders = { + 'x-fp-cli': `${packageJSON.version}`, +}; let headers = { 'Content-Type': 'application/json', Accept: 'application/json', - 'x-fp-cli': `${packageJSON.version}`, + ...cliHeaders, }; export function reload() { @@ -87,6 +93,7 @@ function createPreProxyMiddleware( const url = new URL(currentDomain); req.headers.host = url.host; + Object.assign(req.headers, cliHeaders); // Add signature headers only if required if (withSignature) { @@ -182,6 +189,7 @@ async function requestToOriginalSource(req, res, domain, themeId) { try { const networkRes = await axios.get( urlJoin(domain, url, `?themeId=${themeId}`), + { headers: cliHeaders }, ); publicCache[url] = publicCache[url] || {}; publicCache[url].body = networkRes.data; @@ -568,7 +576,9 @@ export async function startReactServer({ domain, host, isHMREnabled, port }) { skyfireUrl.searchParams.set('themeId', currentContext.theme_id); reqChunkUrl.searchParams.set('themeId', currentContext.theme_id); reqChunkUrl.searchParams.set('url', req.originalUrl); - const response = await axios.get(reqChunkUrl.toString()); + const response = await axios.get(reqChunkUrl.toString(), { + headers: cliHeaders, + }); const requiredFiles = ['themeBundle', ...(response.data || [])]; const User = Configstore.get(CONFIG_KEYS.AUTH_TOKEN);