create-fluxstack 1.8.1 → 1.8.3
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.
- package/.env.example +19 -0
- package/README.md +6 -3
- package/app/client/SIMPLIFICATION.md +140 -0
- package/app/client/frontend-only.ts +1 -1
- package/app/client/src/App.tsx +148 -283
- package/app/client/src/index.css +5 -20
- package/app/client/src/lib/eden-api.ts +53 -220
- package/app/client/src/main.tsx +2 -3
- package/app/server/controllers/users.controller.ts +57 -31
- package/app/server/index.ts +5 -2
- package/app/server/live/register-components.ts +18 -7
- package/app/server/routes/env-test.ts +53 -2
- package/app/server/routes/index.ts +1 -8
- package/app/server/routes/users.routes.ts +192 -91
- package/config/fluxstack.config.ts +2 -2
- package/config/plugins.config.ts +22 -1
- package/core/build/flux-plugins-generator.ts +5 -5
- package/core/build/live-components-generator.ts +15 -12
- package/core/cli/command-registry.ts +4 -14
- package/core/cli/commands/plugin-deps.ts +8 -8
- package/core/cli/generators/component.ts +3 -3
- package/core/cli/generators/controller.ts +4 -4
- package/core/cli/generators/index.ts +8 -8
- package/core/cli/generators/interactive.ts +4 -4
- package/core/cli/generators/plugin.ts +3 -3
- package/core/cli/generators/prompts.ts +1 -1
- package/core/cli/generators/route.ts +27 -11
- package/core/cli/generators/service.ts +5 -5
- package/core/cli/generators/template-engine.ts +1 -1
- package/core/cli/generators/types.ts +1 -1
- package/core/cli/index.ts +158 -193
- package/core/cli/plugin-discovery.ts +3 -3
- package/core/client/hooks/index.ts +2 -2
- package/core/client/hooks/state-validator.ts +1 -1
- package/core/client/hooks/useAuth.ts +1 -1
- package/core/client/hooks/useChunkedUpload.ts +1 -1
- package/core/client/hooks/useHybridLiveComponent.ts +1 -1
- package/core/client/hooks/useWebSocket.ts +1 -1
- package/core/config/env.ts +1 -1
- package/core/config/runtime-config.ts +5 -5
- package/core/config/schema.ts +9 -0
- package/core/framework/server.ts +30 -15
- package/core/framework/types.ts +2 -2
- package/core/live/ComponentRegistry.ts +1 -1
- package/core/plugins/built-in/live-components/commands/create-live-component.ts +1 -1
- package/core/plugins/built-in/live-components/index.ts +1 -1
- package/core/plugins/built-in/monitoring/index.ts +65 -161
- package/core/plugins/built-in/static/index.ts +18 -47
- package/core/plugins/built-in/swagger/index.ts +301 -231
- package/core/plugins/built-in/vite/index.ts +74 -109
- package/core/plugins/config.ts +2 -2
- package/core/plugins/dependency-manager.ts +2 -2
- package/core/plugins/discovery.ts +1 -1
- package/core/plugins/executor.ts +2 -2
- package/core/plugins/manager.ts +19 -4
- package/core/plugins/module-resolver.ts +1 -1
- package/core/plugins/registry.ts +3 -3
- package/core/plugins/types.ts +147 -5
- package/core/server/framework.ts +2 -2
- package/core/server/live/ComponentRegistry.ts +9 -26
- package/core/server/live/FileUploadManager.ts +1 -1
- package/core/server/live/auto-generated-components.ts +26 -0
- package/core/server/live/websocket-plugin.ts +211 -19
- package/core/server/middleware/errorHandling.ts +1 -1
- package/core/server/middleware/index.ts +4 -4
- package/core/server/plugins/database.ts +1 -2
- package/core/server/plugins/static-files-plugin.ts +259 -231
- package/core/server/plugins/swagger.ts +1 -1
- package/core/server/services/BaseService.ts +1 -1
- package/core/server/services/ServiceContainer.ts +1 -1
- package/core/server/services/index.ts +4 -4
- package/core/server/standalone.ts +16 -1
- package/core/testing/index.ts +1 -1
- package/core/testing/setup.ts +1 -1
- package/core/utils/logger/startup-banner.ts +7 -33
- package/core/utils/version.ts +6 -6
- package/create-fluxstack.ts +68 -25
- package/package.json +2 -2
- package/plugins/crypto-auth/index.ts +52 -47
- package/plugins/crypto-auth/server/AuthMiddleware.ts +1 -1
- package/plugins/crypto-auth/server/middlewares/helpers.ts +16 -1
- package/vitest.config.ts +11 -2
- package/app/client/src/App.css +0 -883
- package/app/client/src/components/ErrorBoundary.tsx +0 -107
- package/app/client/src/components/ErrorDisplay.css +0 -365
- package/app/client/src/components/ErrorDisplay.tsx +0 -258
- package/app/client/src/components/FluxStackConfig.tsx +0 -1321
- package/app/client/src/components/HybridLiveCounter.tsx +0 -140
- package/app/client/src/components/LiveClock.tsx +0 -286
- package/app/client/src/components/MainLayout.tsx +0 -388
- package/app/client/src/components/SidebarNavigation.tsx +0 -391
- package/app/client/src/components/StateDemo.tsx +0 -178
- package/app/client/src/components/SystemMonitor.tsx +0 -1044
- package/app/client/src/components/UserProfile.tsx +0 -809
- package/app/client/src/hooks/useAuth.ts +0 -39
- package/app/client/src/hooks/useNotifications.ts +0 -56
- package/app/client/src/lib/errors.ts +0 -340
- package/app/client/src/lib/hooks/useErrorHandler.ts +0 -258
- package/app/client/src/lib/index.ts +0 -45
- package/app/client/src/pages/ApiDocs.tsx +0 -182
- package/app/client/src/pages/CryptoAuthPage.tsx +0 -394
- package/app/client/src/pages/Demo.tsx +0 -174
- package/app/client/src/pages/HybridLive.tsx +0 -263
- package/app/client/src/pages/Overview.tsx +0 -155
- package/app/client/src/store/README.md +0 -43
- package/app/client/src/store/index.ts +0 -16
- package/app/client/src/store/slices/uiSlice.ts +0 -151
- package/app/client/src/store/slices/userSlice.ts +0 -161
- package/app/client/src/test/README.md +0 -257
- package/app/client/src/test/setup.ts +0 -70
- package/app/client/src/test/types.ts +0 -12
- package/app/server/live/CounterComponent.ts +0 -191
- package/app/server/live/FluxStackConfig.ts +0 -534
- package/app/server/live/SidebarNavigation.ts +0 -157
- package/app/server/live/SystemMonitor.ts +0 -595
- package/app/server/live/SystemMonitorIntegration.ts +0 -151
- package/app/server/live/UserProfileComponent.ts +0 -141
- package/app/server/middleware/auth.ts +0 -136
- package/app/server/middleware/errorHandling.ts +0 -252
- package/app/server/middleware/index.ts +0 -10
- package/app/server/middleware/rateLimit.ts +0 -193
- package/app/server/middleware/requestLogging.ts +0 -215
- package/app/server/middleware/validation.ts +0 -270
- package/app/server/routes/config.ts +0 -145
- package/app/server/routes/crypto-auth-demo.routes.ts +0 -167
- package/app/server/routes/example-with-crypto-auth.routes.ts +0 -235
- package/app/server/routes/exemplo-posts.routes.ts +0 -161
- package/app/server/routes/upload.ts +0 -92
- package/app/server/services/NotificationService.ts +0 -302
- package/app/server/services/UserService.ts +0 -222
- package/app/server/services/index.ts +0 -46
- package/app/server/types/index.ts +0 -1
|
@@ -1,231 +1,301 @@
|
|
|
1
|
-
import { swagger } from '@elysiajs/swagger'
|
|
2
|
-
import type { FluxStack, PluginContext } from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
|
|
1
|
+
import { swagger } from '@elysiajs/swagger'
|
|
2
|
+
import type { FluxStack, PluginContext } from '@/core/plugins/types'
|
|
3
|
+
import { appConfig } from '@/config/app.config'
|
|
4
|
+
import { serverConfig } from '@/config/server.config'
|
|
5
|
+
import { pluginsConfig } from '@/config/plugins.config'
|
|
6
|
+
|
|
7
|
+
type Plugin = FluxStack.Plugin
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parse servers from config string
|
|
11
|
+
* Format: "url1|description1,url2|description2"
|
|
12
|
+
*/
|
|
13
|
+
function parseServersFromConfig(serversString: string): Array<{ url: string; description: string }> {
|
|
14
|
+
if (!serversString || serversString.trim() === '') {
|
|
15
|
+
return []
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return serversString.split(',').map(server => {
|
|
19
|
+
const [url, description] = server.split('|').map(s => s.trim())
|
|
20
|
+
return {
|
|
21
|
+
url: url || '',
|
|
22
|
+
description: description || 'Server'
|
|
23
|
+
}
|
|
24
|
+
}).filter(s => s.url !== '')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Configuration from config/plugins.config.ts (user editable)
|
|
28
|
+
const DEFAULTS = {
|
|
29
|
+
enabled: pluginsConfig.swaggerEnabled,
|
|
30
|
+
path: pluginsConfig.swaggerPath,
|
|
31
|
+
title: pluginsConfig.swaggerTitle,
|
|
32
|
+
description: pluginsConfig.swaggerDescription,
|
|
33
|
+
version: pluginsConfig.swaggerVersion,
|
|
34
|
+
excludePaths: pluginsConfig.swaggerExcludePaths,
|
|
35
|
+
servers: parseServersFromConfig(pluginsConfig.swaggerServers),
|
|
36
|
+
|
|
37
|
+
// Swagger UI options
|
|
38
|
+
swaggerOptions: {
|
|
39
|
+
persistAuthorization: pluginsConfig.swaggerPersistAuthorization,
|
|
40
|
+
displayRequestDuration: pluginsConfig.swaggerDisplayRequestDuration,
|
|
41
|
+
filter: pluginsConfig.swaggerEnableFilter,
|
|
42
|
+
showExtensions: pluginsConfig.swaggerShowExtensions,
|
|
43
|
+
tryItOutEnabled: pluginsConfig.swaggerTryItOutEnabled
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
// Authentication
|
|
47
|
+
authEnabled: pluginsConfig.swaggerAuthEnabled,
|
|
48
|
+
authUsername: pluginsConfig.swaggerAuthUsername,
|
|
49
|
+
authPassword: pluginsConfig.swaggerAuthPassword,
|
|
50
|
+
|
|
51
|
+
// Security (can be extended via env vars if needed)
|
|
52
|
+
securitySchemes: {},
|
|
53
|
+
globalSecurity: [] as Array<Record<string, any>>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const swaggerPlugin: Plugin = {
|
|
57
|
+
name: 'swagger',
|
|
58
|
+
version: '1.0.0',
|
|
59
|
+
description: 'Swagger documentation plugin for FluxStack with automatic tag discovery',
|
|
60
|
+
author: 'FluxStack Team',
|
|
61
|
+
priority: 500,
|
|
62
|
+
category: 'documentation',
|
|
63
|
+
tags: ['swagger', 'documentation', 'api'],
|
|
64
|
+
dependencies: [],
|
|
65
|
+
|
|
66
|
+
setup: async (context: PluginContext) => {
|
|
67
|
+
if (!DEFAULTS.enabled) {
|
|
68
|
+
context.logger.debug('Swagger plugin disabled by configuration')
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
// Build servers list
|
|
74
|
+
const servers = DEFAULTS.servers.length > 0 ? DEFAULTS.servers : [
|
|
75
|
+
{
|
|
76
|
+
url: `http://${serverConfig.server.host}:${serverConfig.server.port}`,
|
|
77
|
+
description: 'Development server'
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
// Add production server if in production
|
|
82
|
+
if (context.utils.isProduction()) {
|
|
83
|
+
servers.push({
|
|
84
|
+
url: 'https://api.example.com', // This would be configured
|
|
85
|
+
description: 'Production server'
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Simple Swagger configuration - all options from config/plugins.config.ts
|
|
90
|
+
const swaggerConfig = {
|
|
91
|
+
path: DEFAULTS.path,
|
|
92
|
+
documentation: {
|
|
93
|
+
info: {
|
|
94
|
+
title: DEFAULTS.title || appConfig.name || 'FluxStack API',
|
|
95
|
+
version: DEFAULTS.version || appConfig.version,
|
|
96
|
+
description: DEFAULTS.description || appConfig.description || 'Modern full-stack TypeScript framework with type-safe API endpoints'
|
|
97
|
+
},
|
|
98
|
+
servers,
|
|
99
|
+
|
|
100
|
+
// Add security schemes if defined
|
|
101
|
+
...(Object.keys(DEFAULTS.securitySchemes).length > 0 && {
|
|
102
|
+
components: {
|
|
103
|
+
securitySchemes: DEFAULTS.securitySchemes
|
|
104
|
+
}
|
|
105
|
+
}),
|
|
106
|
+
|
|
107
|
+
// Add global security if defined
|
|
108
|
+
...(DEFAULTS.globalSecurity.length > 0 && {
|
|
109
|
+
security: DEFAULTS.globalSecurity
|
|
110
|
+
})
|
|
111
|
+
},
|
|
112
|
+
exclude: DEFAULTS.excludePaths,
|
|
113
|
+
swaggerOptions: DEFAULTS.swaggerOptions
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Add Basic Auth middleware if enabled
|
|
117
|
+
if (DEFAULTS.authEnabled && DEFAULTS.authPassword) {
|
|
118
|
+
context.app.onBeforeHandle({ as: 'global' }, ({ request, set, path }) => {
|
|
119
|
+
// Only protect Swagger routes
|
|
120
|
+
if (!path.startsWith(DEFAULTS.path)) {
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const authHeader = request.headers.get('authorization')
|
|
125
|
+
|
|
126
|
+
if (!authHeader || !authHeader.startsWith('Basic ')) {
|
|
127
|
+
set.status = 401
|
|
128
|
+
set.headers['WWW-Authenticate'] = 'Basic realm="Swagger Documentation"'
|
|
129
|
+
return {
|
|
130
|
+
error: 'Authentication required',
|
|
131
|
+
message: 'Please provide valid credentials to access Swagger documentation'
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Decode Basic Auth credentials
|
|
136
|
+
const base64Credentials = authHeader.substring(6)
|
|
137
|
+
const credentials = Buffer.from(base64Credentials, 'base64').toString('utf-8')
|
|
138
|
+
const [username, password] = credentials.split(':')
|
|
139
|
+
|
|
140
|
+
// Validate credentials
|
|
141
|
+
if (username !== DEFAULTS.authUsername || password !== DEFAULTS.authPassword) {
|
|
142
|
+
set.status = 401
|
|
143
|
+
set.headers['WWW-Authenticate'] = 'Basic realm="Swagger Documentation"'
|
|
144
|
+
return {
|
|
145
|
+
error: 'Invalid credentials',
|
|
146
|
+
message: 'The provided username or password is incorrect'
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Credentials valid, continue to Swagger
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
context.logger.debug(`🔒 Swagger authentication enabled (username: ${DEFAULTS.authUsername})`)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// That's it! Elysia Swagger auto-discovers everything else
|
|
157
|
+
context.app.use(swagger(swaggerConfig))
|
|
158
|
+
|
|
159
|
+
context.logger.debug(`Swagger documentation enabled at ${DEFAULTS.path}`, {
|
|
160
|
+
title: swaggerConfig.documentation.info.title,
|
|
161
|
+
version: swaggerConfig.documentation.info.version,
|
|
162
|
+
servers: servers.length,
|
|
163
|
+
authEnabled: DEFAULTS.authEnabled
|
|
164
|
+
})
|
|
165
|
+
} catch (error) {
|
|
166
|
+
context.logger.error('Failed to setup Swagger plugin', { error })
|
|
167
|
+
throw error
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
onServerStart: async (context: PluginContext) => {
|
|
172
|
+
if (DEFAULTS.enabled) {
|
|
173
|
+
const swaggerUrl = `http://${serverConfig.server.host}:${serverConfig.server.port}${DEFAULTS.path}`
|
|
174
|
+
context.logger.debug(`📋 Swagger documentation available at: ${swaggerUrl}`)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ==========================================
|
|
180
|
+
// ⚙️ SWAGGER CONFIGURATION
|
|
181
|
+
// ==========================================
|
|
182
|
+
//
|
|
183
|
+
// All Swagger options are configurable via:
|
|
184
|
+
// 📁 config/plugins.config.ts (user editable)
|
|
185
|
+
// 🌍 Environment variables (.env file)
|
|
186
|
+
//
|
|
187
|
+
// Available configurations:
|
|
188
|
+
//
|
|
189
|
+
// 1️⃣ Basic Settings:
|
|
190
|
+
// - SWAGGER_ENABLED (default: true)
|
|
191
|
+
// - SWAGGER_TITLE (default: 'FluxStack API')
|
|
192
|
+
// - SWAGGER_VERSION (default: app version)
|
|
193
|
+
// - SWAGGER_DESCRIPTION (default: 'API documentation...')
|
|
194
|
+
// - SWAGGER_PATH (default: '/swagger')
|
|
195
|
+
//
|
|
196
|
+
// 2️⃣ Advanced Options:
|
|
197
|
+
// - SWAGGER_EXCLUDE_PATHS (array, default: [])
|
|
198
|
+
// - SWAGGER_SERVERS (format: "url1|desc1,url2|desc2")
|
|
199
|
+
// Example: "https://api.prod.com|Production,https://staging.com|Staging"
|
|
200
|
+
//
|
|
201
|
+
// 3️⃣ Swagger UI Options:
|
|
202
|
+
// - SWAGGER_PERSIST_AUTH (default: true)
|
|
203
|
+
// - SWAGGER_DISPLAY_DURATION (default: true)
|
|
204
|
+
// - SWAGGER_ENABLE_FILTER (default: true)
|
|
205
|
+
// - SWAGGER_SHOW_EXTENSIONS (default: true)
|
|
206
|
+
// - SWAGGER_TRY_IT_OUT (default: true)
|
|
207
|
+
//
|
|
208
|
+
// 4️⃣ Authentication (Basic Auth):
|
|
209
|
+
// - SWAGGER_AUTH_ENABLED (default: false)
|
|
210
|
+
// - SWAGGER_AUTH_USERNAME (default: 'admin')
|
|
211
|
+
// - SWAGGER_AUTH_PASSWORD (required if auth enabled)
|
|
212
|
+
//
|
|
213
|
+
// Example .env configuration:
|
|
214
|
+
// ```
|
|
215
|
+
// SWAGGER_ENABLED=true
|
|
216
|
+
// SWAGGER_TITLE=My API
|
|
217
|
+
// SWAGGER_PATH=/api-docs
|
|
218
|
+
// SWAGGER_SERVERS=https://api.myapp.com|Production,https://staging.myapp.com|Staging
|
|
219
|
+
// SWAGGER_EXCLUDE_PATHS=/internal,/admin
|
|
220
|
+
//
|
|
221
|
+
// # Protect Swagger with Basic Auth
|
|
222
|
+
// SWAGGER_AUTH_ENABLED=true
|
|
223
|
+
// SWAGGER_AUTH_USERNAME=admin
|
|
224
|
+
// SWAGGER_AUTH_PASSWORD=super-secret-password
|
|
225
|
+
// ```
|
|
226
|
+
//
|
|
227
|
+
// 🔒 When authentication is enabled:
|
|
228
|
+
// - Browser will prompt for username/password
|
|
229
|
+
// - All Swagger routes are protected (UI + JSON spec)
|
|
230
|
+
// - Credentials are validated using Basic Auth
|
|
231
|
+
// - Perfect for staging/production environments
|
|
232
|
+
//
|
|
233
|
+
// ==========================================
|
|
234
|
+
// 🏷️ AUTOMATIC TAG DISCOVERY
|
|
235
|
+
// ==========================================
|
|
236
|
+
//
|
|
237
|
+
// ✨ 100% AUTOMATIC - Just add tags to your routes!
|
|
238
|
+
//
|
|
239
|
+
// Example 1 - Simple route:
|
|
240
|
+
// app.get('/products', handler, {
|
|
241
|
+
// detail: {
|
|
242
|
+
// summary: 'Get all products',
|
|
243
|
+
// tags: ['Products', 'Catalog'] // ✅ Auto-discovered!
|
|
244
|
+
// }
|
|
245
|
+
// })
|
|
246
|
+
//
|
|
247
|
+
// Example 2 - Grouped routes:
|
|
248
|
+
// export const ordersRoutes = new Elysia({ prefix: '/orders', tags: ['Orders'] })
|
|
249
|
+
// .get('/', handler, {
|
|
250
|
+
// detail: {
|
|
251
|
+
// summary: 'List orders',
|
|
252
|
+
// tags: ['Orders', 'Management'] // ✅ Auto-discovered!
|
|
253
|
+
// }
|
|
254
|
+
// })
|
|
255
|
+
//
|
|
256
|
+
// Elysia Swagger automatically:
|
|
257
|
+
// - Discovers all tags from routes
|
|
258
|
+
// - Organizes endpoints by tag
|
|
259
|
+
// - Generates OpenAPI spec
|
|
260
|
+
// - Creates interactive UI
|
|
261
|
+
//
|
|
262
|
+
// ==========================================
|
|
263
|
+
// 🔐 SECURITY CONFIGURATION
|
|
264
|
+
// ==========================================
|
|
265
|
+
//
|
|
266
|
+
// To enable security in your FluxStack app, configure like this:
|
|
267
|
+
//
|
|
268
|
+
// plugins: {
|
|
269
|
+
// config: {
|
|
270
|
+
// swagger: {
|
|
271
|
+
// securitySchemes: {
|
|
272
|
+
// bearerAuth: {
|
|
273
|
+
// type: 'http',
|
|
274
|
+
// scheme: 'bearer',
|
|
275
|
+
// bearerFormat: 'JWT'
|
|
276
|
+
// },
|
|
277
|
+
// apiKeyAuth: {
|
|
278
|
+
// type: 'apiKey',
|
|
279
|
+
// in: 'header',
|
|
280
|
+
// name: 'X-API-Key'
|
|
281
|
+
// }
|
|
282
|
+
// },
|
|
283
|
+
// globalSecurity: [
|
|
284
|
+
// { bearerAuth: [] } // Apply JWT auth globally
|
|
285
|
+
// ]
|
|
286
|
+
// }
|
|
287
|
+
// }
|
|
288
|
+
// }
|
|
289
|
+
//
|
|
290
|
+
// Then in your routes, you can override per endpoint:
|
|
291
|
+
// app.get('/public', handler, {
|
|
292
|
+
// detail: { security: [] } // No auth required
|
|
293
|
+
// })
|
|
294
|
+
//
|
|
295
|
+
// app.get('/private', handler, {
|
|
296
|
+
// detail: {
|
|
297
|
+
// security: [{ apiKeyAuth: [] }] // API key required
|
|
298
|
+
// }
|
|
299
|
+
// })
|
|
300
|
+
|
|
301
|
+
export default swaggerPlugin
|