Moonglade

Modern Markdown blogging with AI-powered localization and search.


Mongoose Type Issue

This article discusses the TypeScript type definition deficiencies encountered when performing database refactoring with Mongoose in a NestJS environment. The author points out that whether using `typegoose` or `nestjs/mongoose`, the type system fails to provide effective field constraints and error messages when constructing query filters (`FilterQuery`). Specifically, even if a filter object is assigned properties that do not exist in the Schema, TypeScript does not report an error. This prevents the detection of spelling mistakes or logical errors during the compilation phase, which contradicts the original intent of TypeScript to reduce coding mistakes through strong typing. Given that this issue stems from Mongoose's own type definition mechanism and that TypeORM has poor support for MongoDB, the author ultimately decided to abandon the existing solution and chose to rewrite the Schema and related code to migrate to Prima. This prioritizes type safety and clarity for the development experience, reflecting a focus on the quality of type support when selecting an ORM.

Views 111
2024 mongoose orm study typescript work

nginx Cipher Suite Security Audit

This article documents the company's entire process of identifying and resolving HTTPS cipher suite security vulnerabilities during the Level 3 Classified Protection (MLPS Level 3) assessment. Initially, scanning with the `nmap` tool revealed the presence of insecure cipher suites. Although the Nginx configuration was optimized to disable TLS 1.2 and retain only secure suites, external access tests still indicated issues. By comparing the results of local self-testing, which showed normal behavior, with the anomalies observed from external networks, it was determined that traffic passed through other middleware before reaching Nginx. After consulting with the operations team and reviewing historical purchase records, the root cause was finally identified as an incorrectly configured TLS restriction in the Alibaba Cloud WAF. Disabling the WAF caused the issue to disappear, and the problem was subsequently resolved completely through product upgrades and proper configuration. This experience not only highlighted the importance of configuring front-end middleware in security architectures but also prompted a deep reflection on troubleshooting methodologies: one should follow a logic of narrowing down from a broad scope to a specific one, using the discrepancies between internal and external network tests to quickly locate bottlenecks, thereby avoiding blind trial-and-error. Although inefficient communication with the operations team reduced efficiency during the process, the core lesson lies in establishing clear, progressive troubleshooting thinking, transforming theoretical insights into precise technical localization, and thus efficiently resolving security risks in complex network environments.

Views 200
2023 centos cloud docker nginx security work

Lite Version MongoDB Full-Text Search

This article primarily explores technical solutions for implementing Chinese full-text search in the MongoDB Community Edition. Since the Community Edition does not natively support Chinese word segmentation engines, the author proposes a custom solution based on NestJS, Mongoose, and the `@node-rs/jieba` segmentation library. The article details the use of Docker to deploy a MongoDB environment with replica set support, ensuring service stability through a health check mechanism. In terms of architecture, the project is organized using a Monorepo pattern. By listening to database change events, Chinese text is automatically segmented and written back to the collection upon data insertion, thereby constructing a full-text index that supports Chinese retrieval. This solution not only implements basic query functionality but also covers multi-entity detection, value object handling, and a comparative analysis with Elasticsearch, providing developers with a complete technical practice reference for achieving efficient Chinese search at low cost in constrained environments.

Views 175
docker fulltext mongodb nest node search study work

OpenAPI client generation

This article documents the selection process and practical experience of automatically generating SDKs based on OpenAPI metadata. The author compared three libraries: `autorest`, `swagger-codegen-cli`, and `@hey-api/openapi-ts`, ultimately choosing the latter due to its superior performance in frontend environment compatibility, code conciseness, and type reuse. This choice effectively reduces the workload of manually writing request code and improves development efficiency. Using a NestJS backend and Vue frontend as examples, the article details the complete technical pipeline: configuring `nest-cli.json` to extract DTO and Entity types, utilizing a GitHub Actions pipeline to start the service in a CI environment to retrieve metadata, invoking `@hey-api/openapi-ts` to generate the SDK, and pushing it to a separate sub-repository. The frontend wraps the `@hey-api/client-fetch` client to implement unified authentication interception and error handling, directly importing the generated types and functions within Pinia Stores to achieve type safety and code reuse. This workflow not only reduces the collaboration cost between frontend and backend teams but also minimizes format errors through standardized interface definitions. Although the currently auto-generated parameter validation feature has limitations, the overall solution offers significant advantages in terms of type safety and development efficiency.

Views 385
2024 ci-cd github openapi study swagger vue work

Upgrading umijs 3 to 4

This article documents the complete process and insights gained from upgrading the frontend framework of a legacy project from UmiJS 3 to UmiJS 4. The upgrade aims to address low development efficiency, clean up redundant code and libraries, and strengthen engineering standards such as TypeScript and ESLint. The author adopted a strategy of creating a new UmiJS 4 project and gradually migrating code, ensuring functionality stability before merging back into the original project. Specific changes include: replacing configurations with @umijs/max, removing dependencies on webpack-chain, proxy, and mock; rewriting the permission system to support dynamic routing and menus; refactoring class components into function components and introducing Hooks; updating Ant Design to the latest version and removing Less dependencies; deprecating umi-request in favor of axios; and adjusting tsconfig and internationalization configurations. Although specific errors were not detailed in this record, compatibility issues were successfully resolved through official documentation and community assistance, providing a practical reference for similar project upgrades.

Views 126
2024 configuration migration react ts umijs upgrade work

Creating Ventoy Ubuntu 24.04

This article documents the process of installing Ubuntu 24.04 on a new host. Motivated by the release of the new system and the appeal of the updated icons, the author decided to upgrade from the previous version to Ubuntu 24.04. The core of the operation lies in leveraging the Ventoy tool to simplify the installation workflow, eliminating the need for complex preparation; one only needs to download the corresponding ISO image and drag it into the drive. Because the existing Ventoy version was outdated, the author first moved the image files, upgraded Ventoy to the latest version to ensure support for the new system, and then restored the files to their original locations to complete the preparation. The article specifically notes that Ventoy may encounter compatibility issues with older motherboards or BIOS settings (such as matching LEGACY and UEFI modes). It is recommended that users consult the official compatibility list before proceeding to verify support, ensuring a smooth entry into the installation interface. Overall, this is an efficient and convenient method for installing the Linux system.

Views 568
Operating System Installation Ventoy daily study ubuntu work

New System Preinstalled Software Record

This document records a checklist for setting up a new host and configuring its environment, aiming to provide a standardized reference for future computer deployments or pre-installation for new employees. The content covers both Windows and Ubuntu systems, listing development tools and daily-use applications for each. The core of the development environment includes VS Code Insiders, Git, Docker, K8s, as well as database tools DBeaver and MongoDB Compass. For network proxy solutions, v2rayN or Clash is recommended for Windows, while alternatives such as Qv2ray are mentioned for Ubuntu. Regarding daily applications, cross-platform tools such as Edge, VLC, Calibre, and OBS are prioritized, and Windows-specific utilities like Listary and CopyQ are also included. Additionally, the article compiles key resources required for private cloud drive synchronization, including SSH keys, proxy configurations, and Docker mirror sources. It also provides specific configuration commands for SSH proxy forwarding on both Windows and Ubuntu, facilitating quick reuse and enabling an efficient, systematic installation process.

Views 82
Operating System Setup Software Installation daily env study work