@mindexec/cli 0.2.341 → 0.2.342

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +59 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindexec/cli",
3
- "version": "0.2.341",
3
+ "version": "0.2.342",
4
4
  "description": "MindExec local runtime and bridge CLI",
5
5
  "main": "server.js",
6
6
  "type": "module",
package/server.js CHANGED
@@ -1588,8 +1588,15 @@ const CONTENT_TYPE_BY_EXTENSION = new Map([
1588
1588
  ['.mov', 'video/quicktime'],
1589
1589
  ['.m4v', 'video/mp4'],
1590
1590
  ['.pdf', 'application/pdf'],
1591
- ['.txt', 'text/plain; charset=utf-8'],
1592
- ['.json', 'application/json; charset=utf-8']
1591
+ ['.js', 'text/javascript; charset=utf-8'],
1592
+ ['.mjs', 'text/javascript; charset=utf-8'],
1593
+ ['.css', 'text/css; charset=utf-8'],
1594
+ ['.html', 'text/html; charset=utf-8'],
1595
+ ['.txt', 'text/plain; charset=utf-8'],
1596
+ ['.json', 'application/json; charset=utf-8'],
1597
+ ['.map', 'application/json; charset=utf-8'],
1598
+ ['.webmanifest', 'application/manifest+json; charset=utf-8'],
1599
+ ['.wasm', 'application/wasm']
1593
1600
  ]);
1594
1601
 
1595
1602
  function detectContentTypeFromHeader(header) {
@@ -2000,6 +2007,47 @@ app.get('/api/assets/resolve', async (req, res) => {
2000
2007
  });
2001
2008
  });
2002
2009
 
2010
+ async function trySendPackagedWebAppAsset(req, res, mountPath) {
2011
+ if (!WEB_APP_ROOT || !['GET', 'HEAD'].includes(String(req.method || '').toUpperCase())) {
2012
+ return false;
2013
+ }
2014
+
2015
+ let requestPath = getMountedAssetRequestPath(req, mountPath);
2016
+ try {
2017
+ requestPath = decodeURIComponent(requestPath);
2018
+ } catch {
2019
+ return false;
2020
+ }
2021
+
2022
+ if (!requestPath || requestPath.includes('\0')) {
2023
+ return false;
2024
+ }
2025
+
2026
+ const packagedAssetsRoot = path.resolve(WEB_APP_ROOT, String(mountPath || '').replace(/^\/+/, ''));
2027
+ const packagedAssetPath = path.resolve(packagedAssetsRoot, requestPath);
2028
+ if (!isPathWithin(packagedAssetsRoot, packagedAssetPath)) {
2029
+ return false;
2030
+ }
2031
+
2032
+ let stats = null;
2033
+ try {
2034
+ stats = await fs.stat(packagedAssetPath);
2035
+ } catch {
2036
+ return false;
2037
+ }
2038
+
2039
+ if (!stats.isFile()) {
2040
+ return false;
2041
+ }
2042
+
2043
+ await sendResolvedAssetFile(req, res, packagedAssetPath, {
2044
+ notFoundMessage: 'Web app asset not found',
2045
+ errorScope: 'web',
2046
+ cacheControl: 'public, max-age=31536000, immutable'
2047
+ });
2048
+ return true;
2049
+ }
2050
+
2003
2051
  // Static file serving for assets (direct image loading - bypasses base64 encoding)
2004
2052
  // This allows browsers to directly fetch images via http://127.0.0.1:5147/assets/filename.png
2005
2053
  app.use('/assets', async (req, res, next) => {
@@ -2034,11 +2082,15 @@ app.use('/assets', async (req, res, next) => {
2034
2082
  normalizedRequestPath,
2035
2083
  ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp', '.svg', '.mp4', '.webm', '.mov']
2036
2084
  );
2037
- }
2038
-
2039
- if (!resolvedPath) {
2040
- return res.status(404).json({ error: 'Asset not found' });
2041
- }
2085
+ }
2086
+
2087
+ if (!resolvedPath) {
2088
+ if (await trySendPackagedWebAppAsset(req, res, '/assets')) {
2089
+ return;
2090
+ }
2091
+
2092
+ return res.status(404).json({ error: 'Asset not found' });
2093
+ }
2042
2094
 
2043
2095
  return sendResolvedAssetFile(req, res, resolvedPath, {
2044
2096
  notFoundMessage: 'Asset not found',