create-fluxstack 1.0.20 → 1.0.22

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.
@@ -12,7 +12,7 @@ export const vitePlugin: Plugin = {
12
12
  category: "development",
13
13
  tags: ["vite", "development", "hot-reload"],
14
14
  dependencies: [], // No dependencies
15
-
15
+
16
16
  configSchema: {
17
17
  type: "object",
18
18
  properties: {
@@ -51,14 +51,14 @@ export const vitePlugin: Plugin = {
51
51
  description: "Paths to proxy to Vite (defaults to all non-API paths)"
52
52
  },
53
53
  excludePaths: {
54
- type: "array",
54
+ type: "array",
55
55
  items: { type: "string" },
56
56
  description: "Paths to exclude from Vite proxying"
57
57
  }
58
58
  },
59
59
  additionalProperties: false
60
60
  },
61
-
61
+
62
62
  defaultConfig: {
63
63
  enabled: true,
64
64
  port: 5173,
@@ -72,17 +72,17 @@ export const vitePlugin: Plugin = {
72
72
 
73
73
  setup: async (context: PluginContext) => {
74
74
  const config = getPluginConfig(context)
75
-
75
+
76
76
  if (!config.enabled || !context.config.client) {
77
77
  context.logger.info('Vite plugin disabled or no client configuration found')
78
78
  return
79
79
  }
80
-
80
+
81
81
  const vitePort = config.port || context.config.client.port || 5173
82
82
  const viteHost = config.host || "localhost"
83
-
83
+
84
84
  context.logger.info(`🎨 Starting Vite dev server programmatically on ${viteHost}:${vitePort}`)
85
-
85
+
86
86
  try {
87
87
  // Start Vite dev server programmatically
88
88
  viteServer = await createServer({
@@ -93,21 +93,21 @@ export const vitePlugin: Plugin = {
93
93
  host: viteHost
94
94
  }
95
95
  })
96
-
96
+
97
97
  await viteServer.listen()
98
98
  viteServer.printUrls()
99
-
99
+
100
100
  context.logger.info(`✅ Vite server started successfully on ${viteHost}:${vitePort}`)
101
101
  context.logger.info('🔄 Hot reload coordination active - Zero órfãos!')
102
-
103
- // Store Vite config in context for later use
104
- ;(context as any).viteConfig = {
105
- port: vitePort,
106
- host: viteHost,
107
- ...config,
108
- server: viteServer
109
- }
110
-
102
+
103
+ // Store Vite config in context for later use
104
+ ; (context as any).viteConfig = {
105
+ port: vitePort,
106
+ host: viteHost,
107
+ ...config,
108
+ server: viteServer
109
+ }
110
+
111
111
  // Setup cleanup on process exit
112
112
  const cleanup = async () => {
113
113
  if (viteServer) {
@@ -116,21 +116,21 @@ export const vitePlugin: Plugin = {
116
116
  viteServer = null
117
117
  }
118
118
  }
119
-
119
+
120
120
  process.on('SIGINT', cleanup)
121
121
  process.on('SIGTERM', cleanup)
122
122
  process.on('exit', cleanup)
123
-
123
+
124
124
  } catch (error) {
125
125
  context.logger.error('❌ Failed to start Vite server programmatically:', error)
126
126
  context.logger.info('⚠️ Falling back to monitoring mode...')
127
-
128
- // Fallback to monitoring if programmatic start fails
129
- ;(context as any).viteConfig = {
130
- port: vitePort,
131
- host: viteHost,
132
- ...config
133
- }
127
+
128
+ // Fallback to monitoring if programmatic start fails
129
+ ; (context as any).viteConfig = {
130
+ port: vitePort,
131
+ host: viteHost,
132
+ ...config
133
+ }
134
134
  monitorVite(context, viteHost, vitePort, config)
135
135
  }
136
136
  },
@@ -138,45 +138,81 @@ export const vitePlugin: Plugin = {
138
138
  onServerStart: async (context: PluginContext) => {
139
139
  const config = getPluginConfig(context)
140
140
  const viteConfig = (context as any).viteConfig
141
-
141
+
142
142
  if (config.enabled && viteConfig) {
143
143
  context.logger.info(`Vite integration active - monitoring ${viteConfig.host}:${viteConfig.port}`)
144
144
  }
145
145
  },
146
146
 
147
147
  onBeforeRoute: async (requestContext: RequestContext) => {
148
- // Skip API routes, swagger, and ALL Vite internal routes
149
- if (requestContext.path.startsWith("/api") ||
150
- requestContext.path.startsWith("/swagger") ||
151
- requestContext.path.startsWith("/@") || // All Vite internal routes (/@vite/, /@fs/, /@react-refresh, etc.)
152
- requestContext.path.startsWith("/__vite") || // Vite HMR and dev routes
153
- requestContext.path.startsWith("/node_modules") || // Direct node_modules access
154
- requestContext.path.includes("/.vite/") || // Vite cache and deps
155
- requestContext.path.endsWith(".js.map") || // Source maps
156
- requestContext.path.endsWith(".css.map")) { // CSS source maps
148
+ // Skip API routes and swagger - let them be handled by backend
149
+ if (requestContext.path.startsWith("/api") || requestContext.path.startsWith("/swagger")) {
157
150
  return
158
151
  }
159
-
152
+
153
+ // For Vite internal routes, proxy directly to Vite server
154
+ if (requestContext.path.startsWith("/@") || // All Vite internal routes (/@vite/, /@fs/, /@react-refresh, etc.)
155
+ requestContext.path.startsWith("/__vite") || // Vite HMR and dev routes
156
+ requestContext.path.startsWith("/node_modules") || // Direct node_modules access
157
+ requestContext.path.includes("/.vite/") || // Vite cache and deps
158
+ requestContext.path.endsWith(".js.map") || // Source maps
159
+ requestContext.path.endsWith(".css.map")) { // CSS source maps
160
+
161
+ // Use fixed configuration for Vite proxy
162
+ const viteHost = "localhost"
163
+ const vitePort = 5173
164
+
165
+ try {
166
+ const url = new URL(requestContext.request.url)
167
+ const viteUrl = `http://${viteHost}:${vitePort}${requestContext.path}${url.search}`
168
+
169
+ // Forward request to Vite
170
+ const response = await fetch(viteUrl, {
171
+ method: requestContext.method,
172
+ headers: requestContext.headers,
173
+ body: requestContext.method !== 'GET' && requestContext.method !== 'HEAD' ? requestContext.request.body : undefined
174
+ })
175
+
176
+ // Return the Vite response
177
+ const body = await response.arrayBuffer()
178
+
179
+ requestContext.handled = true
180
+ requestContext.response = new Response(body, {
181
+ status: response.status,
182
+ statusText: response.statusText,
183
+ headers: response.headers
184
+ })
185
+
186
+ } catch (viteError) {
187
+ // If Vite fails, let the request continue to normal routing (will become 404)
188
+ // Only log if explicitly enabled for debugging
189
+ if (process.env.ENABLE_VITE_PROXY_LOGS === 'true') {
190
+ console.warn(`Vite proxy error: ${viteError}`)
191
+ }
192
+ }
193
+ return
194
+ }
195
+
160
196
  // Use fixed configuration for simplicity - Vite should be running on port 5173
161
197
  const viteHost = "localhost"
162
198
  const vitePort = 5173
163
-
199
+
164
200
  try {
165
201
  const url = new URL(requestContext.request.url)
166
202
  const viteUrl = `http://${viteHost}:${vitePort}${requestContext.path}${url.search}`
167
-
203
+
168
204
  // Forward request to Vite
169
205
  const response = await fetch(viteUrl, {
170
206
  method: requestContext.method,
171
207
  headers: requestContext.headers,
172
208
  body: requestContext.method !== 'GET' && requestContext.method !== 'HEAD' ? requestContext.request.body : undefined
173
209
  })
174
-
210
+
175
211
  // If Vite responds successfully, handle the request
176
212
  if (response.ok || response.status < 500) {
177
213
  // Return a proper Response object with all headers and status
178
214
  const body = await response.arrayBuffer()
179
-
215
+
180
216
  requestContext.handled = true
181
217
  requestContext.response = new Response(body, {
182
218
  status: response.status,
@@ -184,7 +220,7 @@ export const vitePlugin: Plugin = {
184
220
  headers: response.headers
185
221
  })
186
222
  }
187
-
223
+
188
224
  } catch (viteError) {
189
225
  // If Vite fails, let the request continue to normal routing (will become 404)
190
226
  // Only log if explicitly enabled for debugging
@@ -203,16 +239,16 @@ function getPluginConfig(context: PluginContext) {
203
239
 
204
240
  // Monitor Vite server status with automatic port detection
205
241
  async function monitorVite(
206
- context: PluginContext,
207
- host: string,
208
- initialPort: number,
242
+ context: PluginContext,
243
+ host: string,
244
+ initialPort: number,
209
245
  config: any
210
246
  ) {
211
247
  let retries = 0
212
248
  let isConnected = false
213
249
  let actualPort = initialPort
214
250
  let portDetected = false
215
-
251
+
216
252
  const checkVite = async () => {
217
253
  try {
218
254
  // If we haven't found the correct port yet, try to detect it
@@ -223,13 +259,13 @@ async function monitorVite(
223
259
  portDetected = true
224
260
  // Update the context with the detected port
225
261
  if ((context as any).viteConfig) {
226
- ;(context as any).viteConfig.port = actualPort
262
+ ; (context as any).viteConfig.port = actualPort
227
263
  }
228
264
  }
229
265
  }
230
-
266
+
231
267
  const isRunning = await checkViteRunning(host, actualPort, config.timeout)
232
-
268
+
233
269
  if (isRunning && !isConnected) {
234
270
  isConnected = true
235
271
  retries = 0
@@ -262,11 +298,11 @@ async function monitorVite(
262
298
  context.logger.error('Error checking Vite server status', { error })
263
299
  }
264
300
  }
265
-
301
+
266
302
  // Continue monitoring
267
303
  setTimeout(checkVite, config.checkInterval)
268
304
  }
269
-
305
+
270
306
  // Start monitoring after a brief delay
271
307
  setTimeout(checkVite, 1000)
272
308
  }
@@ -285,7 +321,7 @@ async function detectVitePort(host: string, startPort: number): Promise<number |
285
321
  3000, // Sometimes Vite might use this
286
322
  4173 // Another common alternative
287
323
  ]
288
-
324
+
289
325
  for (const port of portsToTry) {
290
326
  try {
291
327
  const isRunning = await checkViteRunning(host, port, 1000)
@@ -296,7 +332,7 @@ async function detectVitePort(host: string, startPort: number): Promise<number |
296
332
  // Continue trying other ports
297
333
  }
298
334
  }
299
-
335
+
300
336
  return null
301
337
  }
302
338
 
@@ -305,12 +341,12 @@ async function checkViteRunning(host: string, port: number, timeout: number = 10
305
341
  try {
306
342
  const controller = new AbortController()
307
343
  const timeoutId = setTimeout(() => controller.abort(), timeout)
308
-
344
+
309
345
  const response = await fetch(`http://${host}:${port}`, {
310
346
  signal: controller.signal,
311
347
  method: 'HEAD' // Use HEAD to minimize data transfer
312
348
  })
313
-
349
+
314
350
  clearTimeout(timeoutId)
315
351
  return response.status >= 200 && response.status < 500
316
352
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fluxstack",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "⚡ Modern full-stack TypeScript framework with Elysia + React + Bun",
5
5
  "keywords": [
6
6
  "framework",