@eventmodelers/cli 0.0.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.
- package/README.md +175 -0
- package/cli.js +676 -0
- package/package.json +35 -0
- package/shared/build-kit/code-export.mjs +560 -0
- package/shared/build-kit/lib/ollama-agent.js +147 -0
- package/shared/build-kit/package.json +11 -0
- package/shared/build-kit/ralph-ollama.js +39 -0
- package/shared/build-kit/realtime-agent.js +18 -0
- package/stacks/axon/templates/.claude/skills/build-automation/SKILL.md +407 -0
- package/stacks/axon/templates/.claude/skills/build-automation/references/feature-flag-patterns.md +114 -0
- package/stacks/axon/templates/.claude/skills/build-automation-workflow/SKILL.md +496 -0
- package/stacks/axon/templates/.claude/skills/build-automation-workflow/references/axon-workflow-api.md +279 -0
- package/stacks/axon/templates/.claude/skills/build-automation-workflow/references/feature-flag-patterns.md +114 -0
- package/stacks/axon/templates/.claude/skills/build-state-change/SKILL.md +396 -0
- package/stacks/axon/templates/.claude/skills/build-state-change/references/axon-test-fixture-patterns.md +162 -0
- package/stacks/axon/templates/.claude/skills/build-state-change/references/feature-flag-patterns.md +56 -0
- package/stacks/axon/templates/.claude/skills/build-state-change/references/rest-api-patterns.md +115 -0
- package/stacks/axon/templates/.claude/skills/build-state-view/SKILL.md +282 -0
- package/stacks/axon/templates/.claude/skills/connect/SKILL.md +178 -0
- package/stacks/axon/templates/.claude/skills/learn-eventmodelers-api/SKILL.md +611 -0
- package/stacks/axon/templates/.claude/skills/load-slice/SKILL.md +141 -0
- package/stacks/axon/templates/.claude/skills/update-slice-status/SKILL.md +105 -0
- package/stacks/axon/templates/build-kit/lib/AGENT.md +47 -0
- package/stacks/axon/templates/build-kit/lib/agent.sh +20 -0
- package/stacks/axon/templates/build-kit/lib/backend-prompt.md +158 -0
- package/stacks/axon/templates/build-kit/lib/prompt.md +126 -0
- package/stacks/axon/templates/build-kit/lib/ralph.js +369 -0
- package/stacks/axon/templates/build-kit/ralph-claude.js +44 -0
- package/stacks/axon/templates/build-kit/ralph.sh +98 -0
- package/stacks/axon/templates/root/.env.example +5 -0
- package/stacks/axon/templates/root/CLAUDE.md +60 -0
- package/stacks/axon/templates/root/README.md +44 -0
- package/stacks/axon/templates/root/docker-compose.yml +64 -0
- package/stacks/axon/templates/root/mvnw +259 -0
- package/stacks/axon/templates/root/mvnw.cmd +149 -0
- package/stacks/axon/templates/root/pom.xml +125 -0
- package/stacks/axon/templates/root/src/main/java/io/axoniq/quickstart/QuickstartApplication.java +128 -0
- package/stacks/axon/templates/root/src/main/java/io/axoniq/quickstart/config/WebConfig.java +155 -0
- package/stacks/axon/templates/root/src/main/resources/application.properties +2 -0
- package/stacks/axon/templates/root/src/main/resources/static/bg-body.png +0 -0
- package/stacks/axon/templates/root/src/main/resources/static/bg-header.png +0 -0
- package/stacks/axon/templates/root/src/main/resources/static/index.html +596 -0
- package/stacks/cratis-csharp/templates/.claude/skills/_shared/cratis-conventions.md +251 -0
- package/stacks/cratis-csharp/templates/.claude/skills/build-automation/SKILL.md +99 -0
- package/stacks/cratis-csharp/templates/.claude/skills/build-automation/references/patterns.md +115 -0
- package/stacks/cratis-csharp/templates/.claude/skills/build-state-change/SKILL.md +163 -0
- package/stacks/cratis-csharp/templates/.claude/skills/build-state-change/references/patterns.md +234 -0
- package/stacks/cratis-csharp/templates/.claude/skills/build-state-view/SKILL.md +120 -0
- package/stacks/cratis-csharp/templates/.claude/skills/build-state-view/references/patterns.md +166 -0
- package/stacks/cratis-csharp/templates/.claude/skills/connect/SKILL.md +169 -0
- package/stacks/cratis-csharp/templates/.claude/skills/learn-eventmodelers-api/SKILL.md +609 -0
- package/stacks/cratis-csharp/templates/.claude/skills/load-slice/SKILL.md +141 -0
- package/stacks/cratis-csharp/templates/.claude/skills/update-slice-status/SKILL.md +105 -0
- package/stacks/cratis-csharp/templates/build-kit/lib/AGENT.md +58 -0
- package/stacks/cratis-csharp/templates/build-kit/lib/agent.sh +20 -0
- package/stacks/cratis-csharp/templates/build-kit/lib/backend-prompt.md +129 -0
- package/stacks/cratis-csharp/templates/build-kit/lib/prompt.md +124 -0
- package/stacks/cratis-csharp/templates/build-kit/lib/ralph.js +302 -0
- package/stacks/cratis-csharp/templates/build-kit/ralph-claude.js +37 -0
- package/stacks/cratis-csharp/templates/build-kit/ralph.sh +98 -0
- package/stacks/cratis-csharp/templates/root/.frontend/index.css +29 -0
- package/stacks/cratis-csharp/templates/root/.frontend/index.html +17 -0
- package/stacks/cratis-csharp/templates/root/.frontend/main.tsx +18 -0
- package/stacks/cratis-csharp/templates/root/.frontend/tsconfig.json +42 -0
- package/stacks/cratis-csharp/templates/root/.frontend/tsconfig.node.json +11 -0
- package/stacks/cratis-csharp/templates/root/.frontend/vite.config.ts +56 -0
- package/stacks/cratis-csharp/templates/root/App.tsx +23 -0
- package/stacks/cratis-csharp/templates/root/CLAUDE.md +62 -0
- package/stacks/cratis-csharp/templates/root/CratisApp.csproj +25 -0
- package/stacks/cratis-csharp/templates/root/CratisApp.sln +18 -0
- package/stacks/cratis-csharp/templates/root/GlobalUsings.cs +3 -0
- package/stacks/cratis-csharp/templates/root/Home.tsx +102 -0
- package/stacks/cratis-csharp/templates/root/Program.cs +26 -0
- package/stacks/cratis-csharp/templates/root/README.md +192 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Listing/AllListings.ts +47 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Listing/Listing.cs +11 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Listing/Listing.ts +12 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Listing/ListingDataTable.tsx +17 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Listing/index.ts +1 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Registration/Register.ts +51 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Registration/RegisterDialog.tsx +18 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Registration/Registration.cs +27 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/Registration/index.ts +1 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/SomeFeature.tsx +22 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/SomeName.cs +3 -0
- package/stacks/cratis-csharp/templates/root/SomeModule/SomeFeature/index.ts +1 -0
- package/stacks/cratis-csharp/templates/root/appsettings.Development.json +9 -0
- package/stacks/cratis-csharp/templates/root/appsettings.json +26 -0
- package/stacks/cratis-csharp/templates/root/docker-compose.yml +23 -0
- package/stacks/cratis-csharp/templates/root/package.json +33 -0
- package/stacks/cratis-csharp/templates/root/tsconfig.json +3 -0
- package/stacks/modeling-kit/templates/.claude/settings.local.json +13 -0
- package/stacks/modeling-kit/templates/.claude/skills/analyze-existing-model/SKILL.md +215 -0
- package/stacks/modeling-kit/templates/.claude/skills/attributes/SKILL.md +176 -0
- package/stacks/modeling-kit/templates/.claude/skills/connect/SKILL.md +182 -0
- package/stacks/modeling-kit/templates/.claude/skills/discover-storyboard/SKILL.md +383 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-applying-conways-law/SKILL.md +465 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-brainstorming-events/SKILL.md +587 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-brainstorming-events/references/facilitating-event-modeling-workshops.md +626 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-checking-completeness/SKILL.md +542 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-designing-event-models/SKILL.md +497 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-elaborating-scenarios/SKILL.md +783 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-identifying-inputs/SKILL.md +604 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-identifying-outputs/SKILL.md +699 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-integrating-legacy-systems/SKILL.md +674 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-optimizing-stream-design/SKILL.md +231 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-optimizing-stream-design/references/domain-patterns.md +150 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-optimizing-stream-design/references/patterns.md +329 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-optimizing-stream-design/references/snapshotting.md +204 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-orchestrating-event-modeling/SKILL.md +352 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-orchestrating-event-modeling/references/project-planning-with-event-modeling.md +341 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-plotting-events/SKILL.md +153 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-slicing-event-models/SKILL.md +136 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-slicing-event-models/references/examples.md +78 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-slicing-event-models/references/patterns.md +85 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-storyboarding-events/SKILL.md +655 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-translating-external-events/SKILL.md +479 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-validating-event-models/SKILL.md +234 -0
- package/stacks/modeling-kit/templates/.claude/skills/eventmodeling-validating-event-models-checklist/SKILL.md +353 -0
- package/stacks/modeling-kit/templates/.claude/skills/examples/SKILL.md +200 -0
- package/stacks/modeling-kit/templates/.claude/skills/handle-comment/SKILL.md +94 -0
- package/stacks/modeling-kit/templates/.claude/skills/learn-eventmodelers-api/SKILL.md +441 -0
- package/stacks/modeling-kit/templates/.claude/skills/place-element/SKILL.md +290 -0
- package/stacks/modeling-kit/templates/.claude/skills/storyboard/SKILL.md +212 -0
- package/stacks/modeling-kit/templates/.claude/skills/storyboard-screen/SKILL.md +123 -0
- package/stacks/modeling-kit/templates/.claude/skills/timeline/SKILL.md +353 -0
- package/stacks/modeling-kit/templates/.claude/skills/update-slice-status/SKILL.md +110 -0
- package/stacks/modeling-kit/templates/.claude/skills/wdyt/SKILL.md +134 -0
- package/stacks/modeling-kit/templates/kit/lib/agent.sh +20 -0
- package/stacks/modeling-kit/templates/kit/lib/ollama-agent.js +147 -0
- package/stacks/modeling-kit/templates/kit/lib/ralph.js +286 -0
- package/stacks/modeling-kit/templates/kit/package.json +12 -0
- package/stacks/modeling-kit/templates/kit/ralph-claude.js +50 -0
- package/stacks/modeling-kit/templates/kit/ralph-ollama.js +38 -0
- package/stacks/modeling-kit/templates/kit/ralph.sh +61 -0
- package/stacks/modeling-kit/templates/kit/realtime-agent.js +18 -0
- package/stacks/modeling-kit/templates/root/CLAUDE.md +56 -0
- package/stacks/node/templates/.claude/skills/build-automation/SKILL.md +266 -0
- package/stacks/node/templates/.claude/skills/build-state-change/SKILL.md +344 -0
- package/stacks/node/templates/.claude/skills/build-state-view/SKILL.md +412 -0
- package/stacks/node/templates/.claude/skills/connect/SKILL.md +178 -0
- package/stacks/node/templates/.claude/skills/learn-eventmodelers-api/SKILL.md +628 -0
- package/stacks/node/templates/.claude/skills/load-slice/SKILL.md +143 -0
- package/stacks/node/templates/.claude/skills/update-slice-status/SKILL.md +110 -0
- package/stacks/node/templates/build-kit/README.md +86 -0
- package/stacks/node/templates/build-kit/lib/AGENT.md +47 -0
- package/stacks/node/templates/build-kit/lib/agent.sh +20 -0
- package/stacks/node/templates/build-kit/lib/backend-prompt.md +152 -0
- package/stacks/node/templates/build-kit/lib/prompt.md +122 -0
- package/stacks/node/templates/build-kit/lib/ralph.js +369 -0
- package/stacks/node/templates/build-kit/ralph-claude.js +44 -0
- package/stacks/node/templates/build-kit/ralph.sh +98 -0
- package/stacks/node/templates/root/.env.example +15 -0
- package/stacks/node/templates/root/CLAUDE.md +60 -0
- package/stacks/node/templates/root/docker-compose.yml +15 -0
- package/stacks/node/templates/root/flyway.conf +17 -0
- package/stacks/node/templates/root/migrations/V1__schema.sql.example +12 -0
- package/stacks/node/templates/root/package.json +50 -0
- package/stacks/node/templates/root/server.ts +130 -0
- package/stacks/node/templates/root/setup-env.sh +53 -0
- package/stacks/node/templates/root/src/common/assertions.ts +6 -0
- package/stacks/node/templates/root/src/common/db.ts +32 -0
- package/stacks/node/templates/root/src/common/loadPostgresEventstore.ts +23 -0
- package/stacks/node/templates/root/src/common/parseEndpoint.ts +51 -0
- package/stacks/node/templates/root/src/common/processorDlq.ts +28 -0
- package/stacks/node/templates/root/src/common/realtimeBroadcast.ts +12 -0
- package/stacks/node/templates/root/src/common/replay.ts +16 -0
- package/stacks/node/templates/root/src/common/routes.ts +19 -0
- package/stacks/node/templates/root/src/common/testHelpers.ts +44 -0
- package/stacks/node/templates/root/src/swagger.ts +34 -0
- package/stacks/node/templates/root/src/util/assertions.ts +6 -0
- package/stacks/node/templates/root/src/util/hash.ts +9 -0
- package/stacks/node/templates/root/src/util/sanitize.ts +23 -0
- package/stacks/node/templates/root/tsconfig.json +32 -0
- package/stacks/node/templates/root/vercel.json +8 -0
- package/stacks/supabase/templates/.claude/skills/build-automation/SKILL.md +266 -0
- package/stacks/supabase/templates/.claude/skills/build-state-change/SKILL.md +344 -0
- package/stacks/supabase/templates/.claude/skills/build-state-view/SKILL.md +390 -0
- package/stacks/supabase/templates/.claude/skills/build-webhook/SKILL.md +303 -0
- package/stacks/supabase/templates/.claude/skills/connect/SKILL.md +178 -0
- package/stacks/supabase/templates/.claude/skills/learn-eventmodelers-api/SKILL.md +628 -0
- package/stacks/supabase/templates/.claude/skills/load-slice/SKILL.md +143 -0
- package/stacks/supabase/templates/.claude/skills/update-slice-status/SKILL.md +110 -0
- package/stacks/supabase/templates/build-kit/README.md +86 -0
- package/stacks/supabase/templates/build-kit/lib/AGENT.md +47 -0
- package/stacks/supabase/templates/build-kit/lib/agent.sh +20 -0
- package/stacks/supabase/templates/build-kit/lib/backend-prompt.md +152 -0
- package/stacks/supabase/templates/build-kit/lib/prompt.md +123 -0
- package/stacks/supabase/templates/build-kit/lib/ralph.js +369 -0
- package/stacks/supabase/templates/build-kit/ralph-claude.js +44 -0
- package/stacks/supabase/templates/build-kit/ralph.sh +98 -0
- package/stacks/supabase/templates/root/.env.example +22 -0
- package/stacks/supabase/templates/root/CLAUDE.md +61 -0
- package/stacks/supabase/templates/root/flyway.conf +17 -0
- package/stacks/supabase/templates/root/package.json +52 -0
- package/stacks/supabase/templates/root/server.ts +177 -0
- package/stacks/supabase/templates/root/setup-env.sh +53 -0
- package/stacks/supabase/templates/root/src/common/assertions.ts +6 -0
- package/stacks/supabase/templates/root/src/common/db.ts +32 -0
- package/stacks/supabase/templates/root/src/common/loadPostgresEventstore.ts +23 -0
- package/stacks/supabase/templates/root/src/common/parseEndpoint.ts +51 -0
- package/stacks/supabase/templates/root/src/common/processorDlq.ts +28 -0
- package/stacks/supabase/templates/root/src/common/realtimeBroadcast.ts +19 -0
- package/stacks/supabase/templates/root/src/common/replay.ts +16 -0
- package/stacks/supabase/templates/root/src/common/routes.ts +23 -0
- package/stacks/supabase/templates/root/src/common/testHelpers.ts +54 -0
- package/stacks/supabase/templates/root/src/supabase/README.md +141 -0
- package/stacks/supabase/templates/root/src/supabase/api.ts +56 -0
- package/stacks/supabase/templates/root/src/supabase/requireOrgaAdmin.ts +32 -0
- package/stacks/supabase/templates/root/src/supabase/requireSysUser.ts +40 -0
- package/stacks/supabase/templates/root/src/supabase/requireUser.ts +72 -0
- package/stacks/supabase/templates/root/src/swagger.ts +34 -0
- package/stacks/supabase/templates/root/src/util/assertions.ts +6 -0
- package/stacks/supabase/templates/root/src/util/hash.ts +9 -0
- package/stacks/supabase/templates/root/src/util/sanitize.ts +23 -0
- package/stacks/supabase/templates/root/supabase/config.toml +295 -0
- package/stacks/supabase/templates/root/supabase/migrations/V1__schema.sql.example +12 -0
- package/stacks/supabase/templates/root/supabase/seed.sql +1 -0
- package/stacks/supabase/templates/root/tsconfig.json +32 -0
- package/stacks/supabase/templates/root/vercel.json +8 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
package io.axoniq.quickstart.config;
|
|
2
|
+
|
|
3
|
+
import org.springframework.context.annotation.Bean;
|
|
4
|
+
import org.springframework.context.annotation.Configuration;
|
|
5
|
+
import org.springframework.core.io.ClassPathResource;
|
|
6
|
+
import org.springframework.http.MediaType;
|
|
7
|
+
import org.springframework.web.reactive.function.server.RouterFunction;
|
|
8
|
+
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
9
|
+
|
|
10
|
+
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
|
11
|
+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Spring WebFlux configuration for serving static web resources.
|
|
15
|
+
*
|
|
16
|
+
* <p>This configuration class addresses the fundamental difference between Spring MVC and
|
|
17
|
+
* Spring WebFlux regarding static resource handling. Unlike Spring MVC, which automatically
|
|
18
|
+
* serves static resources from {@code src/main/resources/static}, WebFlux requires explicit
|
|
19
|
+
* configuration to handle static file serving.</p>
|
|
20
|
+
*
|
|
21
|
+
* <p><strong>Problem solved:</strong></p>
|
|
22
|
+
* <p>WebFlux applications don't automatically serve static resources, causing 404 errors
|
|
23
|
+
* when trying to access HTML, CSS, JavaScript, and image files. This configuration
|
|
24
|
+
* provides a reactive solution using functional routing.</p>
|
|
25
|
+
*
|
|
26
|
+
* <p><strong>Architecture choice:</strong></p>
|
|
27
|
+
* <p>This implementation uses Spring WebFlux's functional routing approach rather than
|
|
28
|
+
* annotation-based controllers, which aligns with the reactive programming model and
|
|
29
|
+
* provides better performance for static resource serving.</p>
|
|
30
|
+
*
|
|
31
|
+
* <p><strong>Routing strategy:</strong></p>
|
|
32
|
+
* <ul>
|
|
33
|
+
* <li><strong>Root path ({@code /})</strong>: Serves the main index.html file</li>
|
|
34
|
+
* <li><strong>File paths ({@code /{filename}})</strong>: Serves any requested static resource</li>
|
|
35
|
+
* <li><strong>Content-Type detection</strong>: Automatically sets appropriate MIME types</li>
|
|
36
|
+
* <li><strong>404 handling</strong>: Returns proper HTTP 404 for missing resources</li>
|
|
37
|
+
* </ul>
|
|
38
|
+
*
|
|
39
|
+
* <p><strong>Supported file types:</strong></p>
|
|
40
|
+
* <ul>
|
|
41
|
+
* <li>HTML files (text/html)</li>
|
|
42
|
+
* <li>CSS files (text/css)</li>
|
|
43
|
+
* <li>JavaScript files (text/javascript)</li>
|
|
44
|
+
* <li>Images and other files (application/octet-stream)</li>
|
|
45
|
+
* </ul>
|
|
46
|
+
*
|
|
47
|
+
* <p><strong>Security considerations:</strong></p>
|
|
48
|
+
* <ul>
|
|
49
|
+
* <li>Files are served only from the classpath static directory</li>
|
|
50
|
+
* <li>No directory traversal vulnerabilities due to ClassPathResource usage</li>
|
|
51
|
+
* <li>Proper content-type headers prevent MIME-type confusion attacks</li>
|
|
52
|
+
* </ul>
|
|
53
|
+
*
|
|
54
|
+
* <p><strong>Performance characteristics:</strong></p>
|
|
55
|
+
* <ul>
|
|
56
|
+
* <li>Non-blocking I/O through WebFlux reactive streams</li>
|
|
57
|
+
* <li>Efficient resource handling via Spring's ClassPathResource</li>
|
|
58
|
+
* <li>Minimal memory footprint for static file serving</li>
|
|
59
|
+
* </ul>
|
|
60
|
+
*
|
|
61
|
+
* @see RouterFunction
|
|
62
|
+
* @see ServerResponse
|
|
63
|
+
* @see ClassPathResource
|
|
64
|
+
*
|
|
65
|
+
* @author AxonIQ Quickstart
|
|
66
|
+
* @version 1.0
|
|
67
|
+
* @since 1.0
|
|
68
|
+
*/
|
|
69
|
+
@Configuration
|
|
70
|
+
public class WebConfig {
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Creates a functional router for serving static web resources.
|
|
74
|
+
*
|
|
75
|
+
* <p>This bean defines the routing rules for static resource requests using
|
|
76
|
+
* Spring WebFlux's functional routing API. It handles both the root path
|
|
77
|
+
* (serving index.html) and individual file requests with proper content-type
|
|
78
|
+
* detection and 404 error handling.</p>
|
|
79
|
+
*
|
|
80
|
+
* <p><strong>Route definitions:</strong></p>
|
|
81
|
+
* <ol>
|
|
82
|
+
* <li><strong>GET "/"</strong> → serves static/index.html as text/html</li>
|
|
83
|
+
* <li><strong>GET "/{filename}"</strong> → serves static/{filename} with detected content-type</li>
|
|
84
|
+
* </ol>
|
|
85
|
+
*
|
|
86
|
+
* <p><strong>Implementation details:</strong></p>
|
|
87
|
+
* <ul>
|
|
88
|
+
* <li>Uses {@link ClassPathResource} for secure classpath-only access</li>
|
|
89
|
+
* <li>Employs regex pattern {@code /{filename:.+}} to match any filename with extension</li>
|
|
90
|
+
* <li>Automatically detects and sets appropriate MIME types</li>
|
|
91
|
+
* <li>Returns HTTP 404 for non-existent resources</li>
|
|
92
|
+
* </ul>
|
|
93
|
+
*
|
|
94
|
+
* @return RouterFunction that handles static resource requests
|
|
95
|
+
*/
|
|
96
|
+
@Bean
|
|
97
|
+
public RouterFunction<ServerResponse> staticResourceRouter() {
|
|
98
|
+
return route(GET("/"), request ->
|
|
99
|
+
ServerResponse.ok()
|
|
100
|
+
.contentType(MediaType.TEXT_HTML)
|
|
101
|
+
.bodyValue(new ClassPathResource("static/index.html"))
|
|
102
|
+
).andRoute(GET("/{filename:.+}"), request -> {
|
|
103
|
+
String filename = request.pathVariable("filename");
|
|
104
|
+
ClassPathResource resource = new ClassPathResource("static/" + filename);
|
|
105
|
+
|
|
106
|
+
if (resource.exists()) {
|
|
107
|
+
MediaType mediaType = getMediaType(filename);
|
|
108
|
+
return ServerResponse.ok()
|
|
109
|
+
.contentType(mediaType)
|
|
110
|
+
.bodyValue(resource);
|
|
111
|
+
} else {
|
|
112
|
+
return ServerResponse.notFound().build();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Determines the appropriate MIME type based on file extension.
|
|
119
|
+
*
|
|
120
|
+
* <p>This utility method provides content-type detection for common web resource
|
|
121
|
+
* file types, ensuring that browsers receive proper MIME type headers for
|
|
122
|
+
* correct rendering and security.</p>
|
|
123
|
+
*
|
|
124
|
+
* <p><strong>Supported extensions:</strong></p>
|
|
125
|
+
* <ul>
|
|
126
|
+
* <li><strong>.html</strong> → text/html</li>
|
|
127
|
+
* <li><strong>.css</strong> → text/css</li>
|
|
128
|
+
* <li><strong>.js</strong> → text/javascript</li>
|
|
129
|
+
* <li><strong>others</strong> → application/octet-stream (binary default)</li>
|
|
130
|
+
* </ul>
|
|
131
|
+
*
|
|
132
|
+
* <p><strong>Security benefit:</strong></p>
|
|
133
|
+
* <p>Setting correct content-type headers prevents browsers from performing
|
|
134
|
+
* MIME-type sniffing, which could lead to security vulnerabilities when
|
|
135
|
+
* user-uploaded content is served.</p>
|
|
136
|
+
*
|
|
137
|
+
* <p><strong>Extensibility:</strong></p>
|
|
138
|
+
* <p>Additional file types can be easily added by extending the if-else chain
|
|
139
|
+
* or by implementing a more sophisticated mapping strategy for production use.</p>
|
|
140
|
+
*
|
|
141
|
+
* @param filename the name of the file including its extension
|
|
142
|
+
* @return the appropriate MediaType for the file
|
|
143
|
+
*/
|
|
144
|
+
private MediaType getMediaType(String filename) {
|
|
145
|
+
if (filename.endsWith(".html")) {
|
|
146
|
+
return MediaType.TEXT_HTML;
|
|
147
|
+
} else if (filename.endsWith(".css")) {
|
|
148
|
+
return MediaType.valueOf("text/css");
|
|
149
|
+
} else if (filename.endsWith(".js")) {
|
|
150
|
+
return MediaType.valueOf("text/javascript");
|
|
151
|
+
} else {
|
|
152
|
+
return MediaType.APPLICATION_OCTET_STREAM;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
Binary file
|