Skip to content

Conversation

davemarco
Copy link
Contributor

@davemarco davemarco commented Jul 15, 2025

Description

PR flattens fastify-v2 directory into src, and removes all references to V1 architecture. The PR also removes remaining NODE ENV references. This is a chain of PRs which started with #1027

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Tested webui in package

Summary by CodeRabbit

  • New Features

    • Improved server application structure with enhanced plugin and route registration, centralized error handling, and rate-limited 404 responses.
    • Static file serving is now always enabled, regardless of environment.
  • Refactor

    • Simplified and updated import paths throughout the server codebase for better maintainability.
    • Consolidated server entry points for streamlined application startup.
  • Chores

    • Updated server startup and test scripts for consistency and simplicity.
    • Removed obsolete comments and unused code related to previous server structure.

@davemarco davemarco requested a review from a team as a code owner July 15, 2025 18:25
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

## Walkthrough

This change consolidates the Fastify server setup by replacing the previous `fastify-v2/app.ts` with a new `app.ts` that registers plugins and routes using `fastifyAutoload`, sets unified error and 404 handlers, and updates script paths and import statements throughout the codebase to reflect the new structure. Several import paths are also simplified.

## Changes

| File(s)                                                                                       | Change Summary                                                                                                     |
|-----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| package.json, src/main.ts                                                                     | Updated server start script and import paths to use new `app.ts` entrypoint.                                       |
| src/app.ts, src/fastify-v2/app.ts (deleted)                                                   | Replaced old Fastify app with new consolidated async function for plugin/route registration and error handling.    |
| src/routes/static.ts                                                                          | Static file serving is now always registered, not just in production; removed `process` import.                   |
| src/plugins/app/QueryJobDbManager/index.ts, src/plugins/app/S3Manager/index.ts, src/plugins/app/StreamFileManager.ts | Simplified and corrected relative import paths for settings, typings, and modules.                                 |
| src/plugins/external/mongo.ts, src/plugins/external/mysql.ts                                  | Updated import paths for `settings.json` to be less nested.                                                        |
| src/routes/api/search/index.ts, src/routes/api/search/utils.ts, src/routes/api/search/typings.ts | Shortened import paths for constants, schemas, and settings.                                                       |
| src/routes/api/stream-files/index.ts, src/schemas/stream-files.ts                             | Adjusted import paths for job types, schemas, and settings.                                                        |
| src/plugins/app/socket/MongoSocketIoServer/index.ts, src/plugins/app/socket/MongoSocketIoServer/typings.ts, src/plugins/app/socket/MongoSocketIoServer/MongoWatcherCollection.ts | Shortened import paths for types and modules.                                                                      |
| src/test/example.test.ts                                                                      | Updated import path for route under test.                                                                          |
| src/test/tap.ts                                                                               | Removed obsolete TODO comments about Fastify app and test splitting.                                               |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User
    participant FastifyServer
    participant PluginLoader
    participant RouteLoader

    User->>FastifyServer: Start server (via app.ts)
    FastifyServer->>PluginLoader: Register external plugins
    PluginLoader-->>FastifyServer: Plugins registered
    FastifyServer->>PluginLoader: Register app plugins
    PluginLoader-->>FastifyServer: App plugins registered
    FastifyServer->>RouteLoader: Register routes
    RouteLoader-->>FastifyServer: Routes registered
    FastifyServer->>User: Serve requests, handle errors and 404s

Possibly related PRs

Suggested reviewers

  • junhaoliao

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: ASSERTIVE**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 49a2c1cc338f06b57e96906171a1c8ada2cbfa94 and 0744e5c951d894f4fa13f6e8a680e49c8ebfb45b.

</details>

<details>
<summary>📒 Files selected for processing (3)</summary>

* `components/webui/server/src/routes/api/search/index.ts` (1 hunks)
* `components/webui/server/src/routes/api/stream-files/index.ts` (1 hunks)
* `components/webui/server/src/test/tap.ts` (0 hunks)

</details>

<details>
<summary>💤 Files with no reviewable changes (1)</summary>

* components/webui/server/src/test/tap.ts

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>📓 Path-based instructions (1)</summary>

<details>
<summary>**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}</summary>


 Instructions used from: 

**Sources:**
⚙️ **CodeRabbit Configuration File**


</details>

</details><details>
<summary>🧠 Learnings (3)</summary>

<details>
<summary>📓 Common learnings</summary>

Learnt from: junhaoliao
PR: #939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.


Learnt from: junhaoliao
PR: #596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In components/log-viewer-webui/client/src/api/query.js, the ExtractJsonResp type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.


Learnt from: davemarco
PR: #1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.


Learnt from: junhaoliao
PR: #899
File: components/log-viewer-webui/server/src/main.ts:50-58
Timestamp: 2025-05-13T19:38:31.164Z
Learning: When using Fastify's app.close() method, always wrap it in a try/catch block to properly handle shutdown errors. The close() method returns a Promise that can reject if errors occur during the shutdown process (especially with plugins using onClose hooks), and unhandled rejections could cause the application to hang.


</details>
<details>
<summary>components/webui/server/src/routes/api/stream-files/index.ts (3)</summary>

Learnt from: junhaoliao
PR: #596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In components/log-viewer-webui/client/src/api/query.js, the ExtractJsonResp type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.


Learnt from: davemarco
PR: #1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.


Learnt from: junhaoliao
PR: #647
File: components/log-viewer-webui/server/src/main.ts:8-8
Timestamp: 2024-12-31T19:19:55.032Z
Learning: When "moduleResolution": "node16" is used in a TypeScript project's tsconfig.json, the import file extension is typically expected to be ".js" (or ".cjs"/".mjs"), even if the source code is originally in TypeScript (.ts). This is a part of node16’s resolution behavior.


</details>
<details>
<summary>components/webui/server/src/routes/api/search/index.ts (1)</summary>

Learnt from: junhaoliao
PR: #596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In components/log-viewer-webui/client/src/api/query.js, the ExtractJsonResp type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.


</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (6)</summary><blockquote>

<details>
<summary>components/webui/server/src/routes/api/stream-files/index.ts (3)</summary>

`34-34`: **Excellent adherence to coding guidelines.**

The boolean expression correctly uses `false === EXTRACT_JOB_TYPES.has(extractJobType)` instead of `!EXTRACT_JOB_TYPES.has(extractJobType)`, following the project's coding guidelines.

---

`4-4`: **Import path for settings.json is correct**

Verified that `components/webui/server/src/routes/api/stream-files/index.ts` can successfully import from `../../../../settings.json`. No further action required.

---

`7-8`: **Imports are correct under Node16 module resolution**

Both `EXTRACT_JOB_TYPES` and `StreamFileMetadataSchema` live in `components/webui/server/src/typings` and TypeScript’s `moduleResolution: "node16"` setting allows you to import the `.ts` sources using a `.js` extension. The relative paths in `index.ts` resolve to:

- components/webui/server/src/typings/query.ts  
- components/webui/server/src/typings/stream-files.ts  

No changes are required here.

</details>
<details>
<summary>components/webui/server/src/routes/api/search/index.ts (3)</summary>

`11-11`: **Import path for settings.json verified**

The `settings.json` file is present at the updated location and contains the `MongoDbSearchResultsMetadataCollectionName` property—no further changes required.

---

`17-17`: **Import path for QUERY_JOB_TYPE is correct**

The `query.ts` file lives in `components/webui/server/src/typings`, and all server‐side modules (e.g. `StreamFileManager.ts`, `schemas/stream-files.ts`) import it using the same `../../…/typings/query.js` pattern. TypeScript’s ESM resolution allows importing `.ts` files via `.js` extensions, so no changes are needed here.

---

`10-10`: **✅ Import path validated – no changes required**

We located `components/webui/common/index.ts` at `components/webui/server/src/routes/api/search/../../../../../common/index.ts`, and TypeScript’s Node-style ESM resolution correctly maps the `.js` import specifier to the `.ts` source. The import path is correct as written.

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACJ/ADM0MXwKAAoAdxIBbHgASi4AYRZuSJpIZngiKnF8LAJIcjTIADE0RHE4+QBBCgYEGjFsf0g5PxJmfAl4DCJIAAMvfCIwSZIMijAMrPhZ5tb2+TRubmjINNb7bAFy3Bp6EexESkhaNClmZyZ0ZFt6xwEngCMAIADAA2DQwWAed5TfjCUTiKT8OJhBDfOyoOpxKZoLzwABeHlwULKFSq8BqYXwqI8DV2bXgHXQPT6CMGHhG/nGk2mNMgkSIiXk80Wy3gq0oG0y2R2LQZTMOxXgDGoFIwEIAytxRIzlbivLIADR83qYUjIKYMLzYJSQOJeag0DBTGbEjyzBLy2TLABMO1o8H8SRcKAwdTdc0QPX9gYRyQOGHoJDx5Qwqt5+tGcUoZAY0ipfN4JEm+AekAAagDmb11Gz/BDOrQA9U0z4jXyflyJvmudpnbz4jmMHnkOGSbMAHIAeQAIgBRAD6c4n5Z2ZEmFBqbDDkAkzngKkiELgqDSyQA1ihkNxnKF8Ci0PZKOLkPfrDZR7BqMMSIKsGl1Fgd9IBBH0AHYIXLXF4BeFtTnObUKDiZI2DueQaAZXkI02SAAFUAElTkA2EIxvBhzzQUhjxJH5cUQalLWtJRkEfXpRHPPE2gUDBsQoVMZjQWgoX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E4aGaZo06B+4BuaGWKDyyq2uOeqfuuZjIqnSZkXTbHjQ6rfesnGg3ZRBxF6Be5jVdZgeDRdPI3juJ7jOf3zvZ6A2D47ib2DPJrS+ZkTOK/umA2o0kSohZhxnZQH9a9YQE/gYpvDJ6BYQrYiA0x+cITrPgOhntKcDMEzpaLWgXPtJmB3PYU3vNNS3yDkOK21mOXr6+SFXrz0uVWsvUWX6tXAnTXmzzXqrabK6kLr+upDWK7BrZgV7hmHvwO1YF+rSupPy3O7rJAlYyPCXt5CfNdePkyFovtniRfI7nXxloncy+Z3eSpXxVqWcVqNnEDvd0mbf8raIQTqG7GLhOIcEIQDfg7ViIFkHqxZPfuhwP58hO+LGdgpURFiDUjYKTWYEQJYRHQjYwAmxkPyyo/1YCvMJzocDQRcCnEjLe/kKwZqiCyihA12MQMiBSCL2dxK9r3WlrsCBaxkfJJQAXQqduICnXwPaCTh91oQsA7hodxhIICn2p3dvh5D/YLVemC9a7rYWn7RkdaeAo2FbUODkDEO2/fzih0C5rN1CKIGLBah27SItc1LaALOCnAFQ1ezmcNLvHaiWkmylxOLJhBmCYc6QqCO0D30VChg5gwg+AogUho88SQ5ALsr9iVBywQgFoMMDV2dA+4ukssX8DbiNiOlVUgYZ2B4CtCLEDo7KNQeALBTrwKaHUMwWizgHWC+Qtg5AfYJnot90BLglSitUagpQd4B7HANlC34JDgonKUqPdQCwAo4oagWqElAagGANhFNdQAuBgiIAFwHaCULQAXBExQgzkK4a5F1wABONAD6AYAAgGADATVJqgAAccQMEAIERRgQSA3w0EN8LBAAgwIAINAICNBHwt/hAgBIN8KFTJQvhwIMCHyj5QkBEUDAb4YigBC0BQROIuIHygSAAhNUcQUECQHRGghQRwIEgHym+EMBQRmQOIAID5SIoBA9UdYV8JuG4A7h+KR4cWHFAZAXh7kEUUAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=y-scope/clp&utm_content=1106):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@davemarco davemarco changed the title refactor(webui): Complete migration to new Fastify Architecture by removing log-viewer-webui Fastify app. refactor(webui): Complete migration to new Fastify Architecture by removing log-viewer-webui Fastify app. Jul 15, 2025
@davemarco davemarco requested a review from hoophalab July 15, 2025 18:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🔭 Outside diff range comments (5)
components/webui/server/src/plugins/app/S3Manager/index.ts (1)

53-56: false === error instanceof Error is hard to parse

While this meets the house rule of avoiding !expr, a clearer strict-equality form is:

-if (false === error instanceof Error) {
+if (error instanceof Error === false) {

or simply invert the condition and early-return for readability. Consider codifying this rule in an ESLint preset so future contributors don’t need to remember it manually.

components/webui/server/src/main.ts (1)

47-55: Wrap app.close() in a try/catch to avoid unhandled promise rejections

app.close() can reject if any plugin’s onClose hook fails.
Without a guard, the process may hang or exit with an unhandled-rejection warning.

-    closeWithGrace(
-        {delay: Number(DEFAULT_FASTIFY_CLOSE_GRACE_DELAY)},
-        async ({err}) => {
-            if (err) {
-                app.log.error(err);
-            }
-
-            await app.close();
-        }
-    );
+    closeWithGrace(
+        {delay: Number(DEFAULT_FASTIFY_CLOSE_GRACE_DELAY)},
+        async ({err}) => {
+            if (err) {
+                app.log.error(err);
+            }
+
+            try {
+                await app.close();
+            } catch (closeErr) {
+                app.log.error(closeErr, "Error during graceful shutdown");
+                process.exitCode = 1;
+            }
+        }
+    );
components/webui/server/src/plugins/app/socket/MongoSocketIoServer/MongoWatcherCollection.ts (1)

56-64: hasWatcher can be simplified with Map.has

Current implementation performs an unnecessary lookup & typeof check.

-    hasWatcher (
-        queryId: QueryId,
-    ): boolean {
-        if ("undefined" === typeof this.#queryIdtoWatcherMap.get(queryId)) {
-            return false;
-        }
-
-        return true;
-    }
+    hasWatcher (queryId: QueryId): boolean {
+        return this.#queryIdtoWatcherMap.has(queryId);
+    }
components/webui/server/src/plugins/app/socket/MongoSocketIoServer/index.ts (1)

17-25: Same maintainability concern about long relative path
../../../../../../common/index.js is already six hops up; a path alias would make the intent clearer and avoid accidental breakage if folders move again.

components/webui/server/src/plugins/app/socket/MongoSocketIoServer/typings.ts (1)

9-15: Mirror the alias change here for consistency
If you adopt an alias in the main socket server file, update this import too so both files stay in sync.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27a2235 and 49a2c1c.

📒 Files selected for processing (20)
  • components/webui/server/package.json (1 hunks)
  • components/webui/server/src/app.ts (1 hunks)
  • components/webui/server/src/fastify-v2/app.ts (0 hunks)
  • components/webui/server/src/main.ts (1 hunks)
  • components/webui/server/src/plugins/app/QueryJobDbManager/index.ts (1 hunks)
  • components/webui/server/src/plugins/app/S3Manager/index.ts (1 hunks)
  • components/webui/server/src/plugins/app/StreamFileManager.ts (1 hunks)
  • components/webui/server/src/plugins/app/socket/MongoSocketIoServer/MongoWatcherCollection.ts (1 hunks)
  • components/webui/server/src/plugins/app/socket/MongoSocketIoServer/index.ts (1 hunks)
  • components/webui/server/src/plugins/app/socket/MongoSocketIoServer/typings.ts (1 hunks)
  • components/webui/server/src/plugins/external/mongo.ts (1 hunks)
  • components/webui/server/src/plugins/external/mysql.ts (1 hunks)
  • components/webui/server/src/routes/api/search/index.ts (1 hunks)
  • components/webui/server/src/routes/api/search/typings.ts (1 hunks)
  • components/webui/server/src/routes/api/search/utils.ts (1 hunks)
  • components/webui/server/src/routes/api/stream-files/index.ts (1 hunks)
  • components/webui/server/src/routes/static.ts (1 hunks)
  • components/webui/server/src/schemas/stream-files.ts (1 hunks)
  • components/webui/server/src/test/example.test.ts (1 hunks)
  • components/webui/server/src/test/tap.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • components/webui/server/src/test/tap.ts
  • components/webui/server/src/fastify-v2/app.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🧠 Learnings (19)
📓 Common learnings
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: gibber9809
PR: y-scope/clp#504
File: components/core/src/clp_s/search/kql/CMakeLists.txt:29-29
Timestamp: 2024-10-22T15:36:04.655Z
Learning: When reviewing pull requests, focus on the changes within the PR and avoid commenting on issues outside the scope of the PR.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: junhaoliao
PR: y-scope/clp#899
File: components/log-viewer-webui/server/src/main.ts:50-58
Timestamp: 2025-05-13T19:38:31.164Z
Learning: When using Fastify's `app.close()` method, always wrap it in a try/catch block to properly handle shutdown errors. The close() method returns a Promise that can reject if errors occur during the shutdown process (especially with plugins using onClose hooks), and unhandled rejections could cause the application to hang.
components/webui/server/src/main.ts (5)
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: junhaoliao
PR: y-scope/clp#899
File: components/log-viewer-webui/server/src/main.ts:50-58
Timestamp: 2025-05-13T19:38:31.164Z
Learning: When using Fastify's `app.close()` method, always wrap it in a try/catch block to properly handle shutdown errors. The close() method returns a Promise that can reject if errors occur during the shutdown process (especially with plugins using onClose hooks), and unhandled rejections could cause the application to hang.
Learnt from: junhaoliao
PR: y-scope/clp#899
File: components/log-viewer-webui/server/src/main.ts:50-58
Timestamp: 2025-05-13T19:38:31.164Z
Learning: In Fastify applications, the `app.close()` method returns a Promise that can reject if errors occur during shutdown. Always wrap it in a try/catch block to properly handle shutdown errors and set the process exit code to prevent the application from hanging.
components/webui/server/src/plugins/app/S3Manager/index.ts (3)
Learnt from: haiqi96
PR: y-scope/clp#673
File: components/log-viewer-webui/server/src/routes/query.js:9-10
Timestamp: 2025-01-17T22:33:23.547Z
Learning: When initializing S3Manager in log-viewer-webui, both StreamFilesS3Region and StreamFilesS3PathPrefix settings must be non-null for S3 functionality to work correctly.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
components/webui/server/src/plugins/app/socket/MongoSocketIoServer/MongoWatcherCollection.ts (4)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#880
File: components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/MongoWatcherCollection.ts:79-83
Timestamp: 2025-05-05T18:03:50.472Z
Learning: In MongoWatcherCollection, the unsubscribe method is intentionally designed to remove only one instance of a connection ID from the subscribers array using removeItemFromArray. This allows for multiple subscriptions from the same connection, with each unsubscribe call removing only one subscription at a time.
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:32-38
Timestamp: 2025-05-09T18:05:42.814Z
Learning: When implementing Socket.IO namespaces or connection pooling in a client-server architecture (like the MongoDB collection socket system in the log-viewer-webui), coordinated changes are needed on both client and server sides, making it appropriate to track as a TODO rather than implement piecemeal.
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:27-31
Timestamp: 2025-05-09T19:15:26.180Z
Learning: For the MongoDB real-time updates implementation in components/log-viewer-webui/client/src/api/socket, a socket singleton pattern is used where a single shared socket connection is maintained rather than creating multiple connections. The socket lifecycle is managed centrally, with unsubscription handling in the useCursor React hook's cleanup function.
components/webui/server/src/plugins/app/socket/MongoSocketIoServer/index.ts (5)
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:32-38
Timestamp: 2025-05-09T18:05:42.814Z
Learning: When implementing Socket.IO namespaces or connection pooling in a client-server architecture (like the MongoDB collection socket system in the log-viewer-webui), coordinated changes are needed on both client and server sides, making it appropriate to track as a TODO rather than implement piecemeal.
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:27-31
Timestamp: 2025-05-09T19:15:26.180Z
Learning: For the MongoDB real-time updates implementation in components/log-viewer-webui/client/src/api/socket, a socket singleton pattern is used where a single shared socket connection is maintained rather than creating multiple connections. The socket lifecycle is managed centrally, with unsubscription handling in the useCursor React hook's cleanup function.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: davemarco
PR: y-scope/clp#880
File: components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/MongoWatcherCollection.ts:79-83
Timestamp: 2025-05-05T18:03:50.472Z
Learning: In MongoWatcherCollection, the unsubscribe method is intentionally designed to remove only one instance of a connection ID from the subscribers array using removeItemFromArray. This allows for multiple subscriptions from the same connection, with each unsubscribe call removing only one subscription at a time.
components/webui/server/src/test/example.test.ts (6)
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: davemarco
PR: y-scope/clp#797
File: components/log-viewer-webui/client/src/components/Layout/MainLayout.tsx:2-5
Timestamp: 2025-04-08T22:32:05.366Z
Learning: In this codebase using React Router v7.4.1, components should be imported directly from "react-router" (e.g., `import { Link, Outlet } from "react-router";`) rather than from "react-router-dom" as was common in previous versions of React Router.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#797
File: components/log-viewer-webui/client/src/components/Layout/MainLayout.tsx:2-5
Timestamp: 2025-04-08T22:32:05.367Z
Learning: React Router v7.4.1 uses a different package structure than previous versions. Components can be imported directly from "react-router" (e.g., `import { Link, Outlet } from "react-router";`) rather than from "react-router-dom" as was common in previous versions. Alternatively, DOM-specific components can also be imported using deep imports like `import { Link } from "react-router/dom";`.
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
Learnt from: davemarco
PR: y-scope/clp#797
File: components/log-viewer-webui/client/src/routes/routes.tsx:1-1
Timestamp: 2025-04-04T15:15:59.432Z
Learning: In React Router v7, `createBrowserRouter` and other router primitives should be imported from `react-router` package, not from `react-router-dom` as in previous versions. This represents a significant change in the library's structure where router primitives are now in the core package.
components/webui/server/src/plugins/external/mysql.ts (1)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
components/webui/server/src/routes/api/search/utils.ts (1)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
components/webui/server/src/routes/api/stream-files/index.ts (3)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: junhaoliao
PR: y-scope/clp#647
File: components/log-viewer-webui/server/src/main.ts:8-8
Timestamp: 2024-12-31T19:19:55.032Z
Learning: When "moduleResolution": "node16" is used in a TypeScript project's tsconfig.json, the import file extension is typically expected to be ".js" (or ".cjs"/".mjs"), even if the source code is originally in TypeScript (.ts). This is a part of node16’s resolution behavior.
components/webui/server/src/routes/api/search/typings.ts (1)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
components/webui/server/src/schemas/stream-files.ts (3)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: junhaoliao
PR: y-scope/clp#647
File: components/log-viewer-webui/server/src/main.ts:8-8
Timestamp: 2024-12-31T19:19:55.032Z
Learning: When "moduleResolution": "node16" is used in a TypeScript project's tsconfig.json, the import file extension is typically expected to be ".js" (or ".cjs"/".mjs"), even if the source code is originally in TypeScript (.ts). This is a part of node16’s resolution behavior.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:35-41
Timestamp: 2024-11-19T19:52:43.429Z
Learning: For internal APIs in `components/log-viewer-webui/client/src/api/query.js`, runtime validation of parameters may not be necessary since the APIs are not exposed to end users, and JsDoc type annotations may be sufficient.
components/webui/server/src/plugins/app/StreamFileManager.ts (3)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: junhaoliao
PR: y-scope/clp#647
File: components/log-viewer-webui/server/src/main.ts:8-8
Timestamp: 2024-12-31T19:19:55.032Z
Learning: When "moduleResolution": "node16" is used in a TypeScript project's tsconfig.json, the import file extension is typically expected to be ".js" (or ".cjs"/".mjs"), even if the source code is originally in TypeScript (.ts). This is a part of node16’s resolution behavior.
components/webui/server/src/plugins/app/QueryJobDbManager/index.ts (2)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: junhaoliao
PR: y-scope/clp#647
File: components/log-viewer-webui/server/src/main.ts:8-8
Timestamp: 2024-12-31T19:19:55.032Z
Learning: When "moduleResolution": "node16" is used in a TypeScript project's tsconfig.json, the import file extension is typically expected to be ".js" (or ".cjs"/".mjs"), even if the source code is originally in TypeScript (.ts). This is a part of node16’s resolution behavior.
components/webui/server/src/plugins/app/socket/MongoSocketIoServer/typings.ts (4)
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:32-38
Timestamp: 2025-05-09T18:05:42.814Z
Learning: When implementing Socket.IO namespaces or connection pooling in a client-server architecture (like the MongoDB collection socket system in the log-viewer-webui), coordinated changes are needed on both client and server sides, making it appropriate to track as a TODO rather than implement piecemeal.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:27-31
Timestamp: 2025-05-09T19:15:26.180Z
Learning: For the MongoDB real-time updates implementation in components/log-viewer-webui/client/src/api/socket, a socket singleton pattern is used where a single shared socket connection is maintained rather than creating multiple connections. The socket lifecycle is managed centrally, with unsubscription handling in the useCursor React hook's cleanup function.
Learnt from: junhaoliao
PR: y-scope/clp#647
File: components/log-viewer-webui/server/src/main.ts:8-8
Timestamp: 2024-12-31T19:19:55.032Z
Learning: When "moduleResolution": "node16" is used in a TypeScript project's tsconfig.json, the import file extension is typically expected to be ".js" (or ".cjs"/".mjs"), even if the source code is originally in TypeScript (.ts). This is a part of node16’s resolution behavior.
components/webui/server/src/plugins/external/mongo.ts (2)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: junhaoliao
PR: y-scope/clp#647
File: components/log-viewer-webui/server/src/main.ts:8-8
Timestamp: 2024-12-31T19:19:55.032Z
Learning: When "moduleResolution": "node16" is used in a TypeScript project's tsconfig.json, the import file extension is typically expected to be ".js" (or ".cjs"/".mjs"), even if the source code is originally in TypeScript (.ts). This is a part of node16’s resolution behavior.
components/webui/server/src/routes/api/search/index.ts (1)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
components/webui/server/src/routes/static.ts (2)
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
components/webui/server/package.json (3)
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
components/webui/server/src/app.ts (3)
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
Learnt from: junhaoliao
PR: y-scope/clp#899
File: components/log-viewer-webui/server/src/main.ts:50-58
Timestamp: 2025-05-13T19:38:31.164Z
Learning: When using Fastify's `app.close()` method, always wrap it in a try/catch block to properly handle shutdown errors. The close() method returns a Promise that can reject if errors occur during the shutdown process (especially with plugins using onClose hooks), and unhandled rejections could cause the application to hang.
🧬 Code Graph Analysis (1)
components/webui/server/src/app.ts (2)
components/webui/server/src/plugins/app/socket/MongoSocketIoServer/index.ts (1)
  • FastifyInstance (408-410)
components/webui/server/src/plugins/external/env.ts (1)
  • FastifyInstance (6-15)
🪛 Biome (1.9.4)
components/webui/server/src/app.ts

[error] 29-29: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (12)
components/webui/server/src/plugins/external/mysql.ts (1)

7-8: Import path confirmed

  • The file components/webui/server/settings.json exists, so the import from ../../../settings.json will resolve correctly at runtime.
  • No code changes needed here—just ensure your build/packaging process includes this file in the shipped artefact.
components/webui/server/src/plugins/app/QueryJobDbManager/index.ts (1)

9-10: Path tweaks look good – just make sure the JSON assertion remains transpile-safe

Both import paths were updated correctly and still honour Node 16’s moduleResolution=node16 (note the retained .js file-extension).
Nothing else to flag here.

Also applies to: 16-17

components/webui/server/src/plugins/app/socket/MongoSocketIoServer/MongoWatcherCollection.ts (1)

7-8: Import relocation acknowledged

The shortened path resolves correctly given the flattened directory structure.

components/webui/server/src/schemas/stream-files.ts (1)

3-5: Import path adjustment LGTM

The schema file compiles and the enum reference remains intact.

components/webui/server/src/test/example.test.ts (1)

5-5: Import path update approved – no legacy fastify-v2 references found

  • Verified by running rg --fixed-strings "../fastify-v2" components/webui/server: ✓ No legacy paths found
  • The import in components/webui/server/src/test/example.test.ts remains correct:
    import routes from "../routes/api/example/index.js";
components/webui/server/src/routes/api/stream-files/index.ts (1)

4-6: Import rewiring verified
All three paths resolve correctly under the new directory layout; no issues spotted.

components/webui/server/src/routes/api/search/typings.ts (1)

10-14: Import-path adjustment looks correct – confirm build still resolves.

The shorter relative path to common/index.js aligns with the directory flattening. As this repo uses moduleResolution: "node16", exporting .js is required and looks good. Please run a quick tsc --noEmit to ensure no remaining files still point to the old deeper path.

components/webui/server/src/plugins/external/mongo.ts (1)

3-3: Path change approved, but validate settings file availability in packaged dist.

Moving from ../../../../../../../ is correct after folder flattening. Double-check that the compiled output still copies settings.json into the same relative location (dist/server/settings.json); otherwise Fastify-CLI will fail at runtime.

components/webui/server/src/routes/api/search/index.ts (1)

7-13: All three imports updated – run integration tests for safety.

Nothing functionally changed, but this file is hot-path; a silent mis-path will surface only at runtime. Please execute the existing end-to-end search test suite (or hit /api/search/query) before merging.

components/webui/server/package.json (1)

9-15: Script target updated – confirm tsc outDir matches dist/server.

tsc default outDir is often dist. Because the start scripts now reference dist/server/src/app.js, ensure tsconfig.json sets "rootDir": "src" and "outDir": "dist/server" (or that a post-build move copies correctly). Otherwise production start will 404.

components/webui/server/src/routes/static.ts (1)

40-55: LGTM! Clean removal of environment-specific logic.

The removal of the conditional check for production environment simplifies the code and makes it consistent with the other static directory registrations. The implementation correctly uses decorateReply: true which allows reply.sendFile() to work without specifying the root directory.

components/webui/server/src/app.ts (1)

1-106: Excellent Fastify app architecture with proper plugin loading and error handling.

The migration to fastifyAutoload provides a clean, maintainable structure. The implementation includes:

  • Proper plugin loading order (external → app → routes)
  • Comprehensive error handling with detailed logging
  • Security-conscious rate-limited 404 handler


import settings from "../../../../../settings.json" with {type: "json"};
import {Nullable} from "../../../../typings/common.js";
import settings from "../../../../settings.json" with {type: "json"};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

JSON import assertion syntax may not compile under Node ≥ 20 / TS ≥ 5.4

The current syntax uses the Stage-3 with {type: "json"} clause. Node’s stable implementation – and TypeScript’s emit – expect assert { type: "json" }. Unless your build pipeline rewrites this, the file will fail to transpile / run.

-import settings from "../../../../settings.json" with {type: "json"};
+import settings from "../../../../settings.json" assert { type: "json" };

Please verify the chosen syntax against the toolchain versions in CI.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import settings from "../../../../settings.json" with {type: "json"};
-import settings from "../../../../settings.json" with {type: "json"};
+import settings from "../../../../settings.json" assert { type: "json" };
🤖 Prompt for AI Agents
In components/webui/server/src/plugins/app/S3Manager/index.ts at line 8, the
JSON import uses the syntax 'with {type: "json"}' which may not be compatible
with Node.js version 20 or TypeScript 5.4 and above. Replace this with the
stable syntax 'assert { type: "json" }' to ensure compatibility and successful
transpilation. Verify this change works with the CI toolchain versions.

import settings from "../../../../../settings.json" with {type: "json"};
import {Nullable} from "../../../../typings/common.js";
import settings from "../../../../settings.json" with {type: "json"};
import {Nullable} from "../../../typings/common.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Importing “.js” from TypeScript may generate incorrect dist paths

../../../typings/common.js assumes your emitted files keep the same relative depth and extension mapping. When tsc is configured with "module": "ESNext" and outDir, the compiled path often becomes ../../../typings/common.js in the output directory, but the source file is common.ts. If preserveExtensions is not enabled the import will be wrong at runtime.

Recommend importing the bare module and let TS resolve the .ts:

-import {Nullable} from "../../../typings/common.js";
+import {Nullable} from "../../../typings/common";

or add a paths alias in tsconfig.json to avoid brittle relative traversals.

🤖 Prompt for AI Agents
In components/webui/server/src/plugins/app/S3Manager/index.ts at line 9, the
import statement uses a .js extension which can cause incorrect paths in the
compiled output. To fix this, remove the .js extension from the import path so
TypeScript can resolve the .ts file correctly, or alternatively configure a path
alias in tsconfig.json to avoid fragile relative imports.

Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. This PR is only about moving existing files around.

Validations:

  1. For clp-text and clp-json
  2. Card display is correct
  3. Query works as expected
  4. Extract stream works

Question: This commit doesn't address the "Remove all node environment references from server" task, right?

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deferring to @hoophalab 's review

@davemarco
Copy link
Contributor Author

Question: This commit doesn't address the "Remove all node environment references from server" task, right?
it does. i believe i removed the last 2 - one was in fastify v1 app. The other was in package.json

@davemarco davemarco merged commit 8fc0dd7 into y-scope:main Jul 17, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants