@tpitre/story-ui 3.3.0 → 3.4.1

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.
@@ -1,6 +1,7 @@
1
1
  import dotenv from 'dotenv';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
+ import { createProxyMiddleware } from 'http-proxy-middleware';
4
5
  // Get __dirname equivalent for ES modules
5
6
  const __filename = fileURLToPath(import.meta.url);
6
7
  const __dirname = path.dirname(__filename);
@@ -199,6 +200,37 @@ const config = loadUserConfig();
199
200
  // Initialize URL redirect service
200
201
  const redirectService = new UrlRedirectService(process.cwd());
201
202
  const PORT = parseInt(process.env.PORT || '4001', 10);
203
+ // Storybook proxy configuration for production deployment
204
+ // When STORYBOOK_PROXY_ENABLED is set, proxy all non-API requests to Storybook dev server
205
+ const storybookProxyPort = process.env.STORYBOOK_PROXY_PORT || '6006';
206
+ const storybookProxyEnabled = process.env.STORYBOOK_PROXY_ENABLED === 'true';
207
+ if (storybookProxyEnabled) {
208
+ console.log(`📖 Storybook proxy enabled - forwarding to localhost:${storybookProxyPort}`);
209
+ // Proxy all requests that don't match API routes to Storybook
210
+ // This must be added AFTER all API routes so they take precedence
211
+ app.use('/', createProxyMiddleware({
212
+ target: `http://localhost:${storybookProxyPort}`,
213
+ changeOrigin: true,
214
+ ws: true, // Enable WebSocket proxying for HMR
215
+ logger: console,
216
+ // Don't proxy API routes
217
+ pathFilter: (path) => {
218
+ const isApiRoute = path.startsWith('/mcp') ||
219
+ path.startsWith('/story-ui') ||
220
+ path.startsWith('/mcp-remote');
221
+ return !isApiRoute;
222
+ },
223
+ on: {
224
+ error: (err, req, res) => {
225
+ console.error('Storybook proxy error:', err.message);
226
+ if (res && typeof res.writeHead === 'function' && !res.headersSent) {
227
+ res.writeHead(502, { 'Content-Type': 'text/plain' });
228
+ res.end('Storybook is starting up, please wait...');
229
+ }
230
+ }
231
+ }
232
+ }));
233
+ }
202
234
  // Start server
203
235
  app.listen(PORT, () => {
204
236
  console.log(`MCP server running on port ${PORT}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpitre/story-ui",
3
- "version": "3.3.0",
3
+ "version": "3.4.1",
4
4
  "description": "AI-powered Storybook story generator with dynamic component discovery",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -83,6 +83,7 @@
83
83
  "dotenv": "^16.3.1",
84
84
  "express": "^4.18.2",
85
85
  "glob": "^11.0.3",
86
+ "http-proxy-middleware": "^3.0.0",
86
87
  "inquirer": "^9.2.0",
87
88
  "node-fetch": "^2.6.7",
88
89
  "pg": "^8.16.3",